Add NewS3Client() function

This commit is contained in:
Harshavardhana
2015-01-15 14:45:45 -08:00
parent c5a6e559c0
commit 47735ca12f
2 changed files with 15 additions and 9 deletions
+4
View File
@@ -347,6 +347,10 @@ func (c *Client) Delete(bucket, key string) error {
return fmt.Errorf("Amazon HTTP error on DELETE: %d", res.StatusCode)
}
func NewS3Client(accessKey, secretKey string) *Client {
return &Client{&Auth{AccessKey: accessKey, SecretAccessKey: secretKey}, http.DefaultTransport}
}
// IsValid reports whether bucket is a valid bucket name, per Amazon's naming restrictions.
//
// See http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
+11 -9
View File
@@ -17,7 +17,7 @@ limitations under the License.
package s3
import (
"net/http"
"errors"
"os"
"reflect"
"strings"
@@ -26,15 +26,14 @@ import (
var tc *Client
func getTestClient(t *testing.T) bool {
func getTestClient(t *testing.T) error {
accessKey := os.Getenv("AWS_ACCESS_KEY_ID")
secret := os.Getenv("AWS_ACCESS_KEY_SECRET")
if accessKey == "" || secret == "" {
t.Logf("Skipping test; no AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY_SECRET set in environment")
return false
return errors.New("no AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY_SECRET set in environment")
}
tc = &Client{&Auth{AccessKey: accessKey, SecretAccessKey: secret}, http.DefaultTransport}
return true
tc = NewS3Client(accessKey, secret)
return nil
}
func dumpBuckets(t *testing.T, v []*Bucket) {
@@ -44,10 +43,13 @@ func dumpBuckets(t *testing.T, v []*Bucket) {
}
func TestBuckets(t *testing.T) {
if !getTestClient(t) {
return
var err error
err = getTestClient(t)
if err != nil {
t.Fatal(err)
}
buckets, err := tc.Buckets()
var buckets []*Bucket
buckets, err = tc.Buckets()
if err != nil {
t.Fatal(err)
}