2014-10-24 23:37:25 +00:00
|
|
|
package s3
|
|
|
|
|
|
|
|
import (
|
2014-12-19 17:16:51 +00:00
|
|
|
"io/ioutil"
|
2014-10-24 23:37:25 +00:00
|
|
|
"os"
|
2014-10-29 01:15:40 +00:00
|
|
|
"strconv"
|
2014-10-24 23:37:25 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/crowdmob/goamz/aws"
|
2014-12-24 00:01:38 +00:00
|
|
|
"github.com/docker/distribution/storagedriver"
|
|
|
|
"github.com/docker/distribution/storagedriver/testsuites"
|
2014-11-17 23:44:07 +00:00
|
|
|
|
|
|
|
"gopkg.in/check.v1"
|
2014-10-24 23:37:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Hook up gocheck into the "go test" runner.
|
2014-11-17 23:44:07 +00:00
|
|
|
func Test(t *testing.T) { check.TestingT(t) }
|
2014-10-24 23:37:25 +00:00
|
|
|
|
|
|
|
func init() {
|
2014-10-29 01:15:40 +00:00
|
|
|
accessKey := os.Getenv("AWS_ACCESS_KEY")
|
|
|
|
secretKey := os.Getenv("AWS_SECRET_KEY")
|
2014-10-24 23:37:25 +00:00
|
|
|
bucket := os.Getenv("S3_BUCKET")
|
|
|
|
encrypt := os.Getenv("S3_ENCRYPT")
|
2014-12-29 20:29:54 +00:00
|
|
|
secure := os.Getenv("S3_SECURE")
|
2014-12-19 17:16:51 +00:00
|
|
|
region := os.Getenv("AWS_REGION")
|
|
|
|
root, err := ioutil.TempDir("", "driver-")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-10-24 23:37:25 +00:00
|
|
|
|
2014-12-08 23:47:37 +00:00
|
|
|
s3DriverConstructor := func(region aws.Region) (storagedriver.StorageDriver, error) {
|
2014-12-29 20:29:54 +00:00
|
|
|
encryptBool, err := strconv.ParseBool(encrypt)
|
2014-10-29 01:15:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-12-29 20:29:54 +00:00
|
|
|
|
|
|
|
secureBool := true
|
|
|
|
if secure != "" {
|
|
|
|
secureBool, err = strconv.ParseBool(secure)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return New(accessKey, secretKey, bucket, root, region, encryptBool, secureBool)
|
2014-10-24 23:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 01:15:40 +00:00
|
|
|
// Skip S3 storage driver tests if environment variable parameters are not provided
|
2014-10-27 20:24:07 +00:00
|
|
|
skipCheck := func() string {
|
2014-12-08 23:47:37 +00:00
|
|
|
if accessKey == "" || secretKey == "" || bucket == "" || encrypt == "" {
|
|
|
|
return "Must set AWS_ACCESS_KEY, AWS_SECRET_KEY, S3_BUCKET, and S3_ENCRYPT to run S3 tests"
|
2014-10-27 20:24:07 +00:00
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2014-12-19 17:16:51 +00:00
|
|
|
// for _, region := range aws.Regions {
|
|
|
|
// if region == aws.USGovWest {
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
|
|
|
|
testsuites.RegisterInProcessSuite(func() (storagedriver.StorageDriver, error) {
|
|
|
|
return s3DriverConstructor(aws.GetRegion(region))
|
|
|
|
}, skipCheck)
|
|
|
|
// testsuites.RegisterIPCSuite(driverName, map[string]string{
|
|
|
|
// "accesskey": accessKey,
|
|
|
|
// "secretkey": secretKey,
|
|
|
|
// "region": region.Name,
|
|
|
|
// "bucket": bucket,
|
|
|
|
// "encrypt": encrypt,
|
|
|
|
// }, skipCheck)
|
|
|
|
// }
|
2014-10-24 23:37:25 +00:00
|
|
|
}
|