2014-10-25 01:37:25 +02:00
|
|
|
package s3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2014-10-29 02:15:40 +01:00
|
|
|
"strconv"
|
2014-10-25 01:37:25 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/crowdmob/goamz/aws"
|
|
|
|
"github.com/docker/docker-registry/storagedriver"
|
|
|
|
"github.com/docker/docker-registry/storagedriver/testsuites"
|
|
|
|
. "gopkg.in/check.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Hook up gocheck into the "go test" runner.
|
|
|
|
func Test(t *testing.T) { TestingT(t) }
|
|
|
|
|
|
|
|
func init() {
|
2014-10-29 02:15:40 +01:00
|
|
|
accessKey := os.Getenv("AWS_ACCESS_KEY")
|
|
|
|
secretKey := os.Getenv("AWS_SECRET_KEY")
|
2014-10-25 01:37:25 +02:00
|
|
|
region := os.Getenv("AWS_REGION")
|
|
|
|
bucket := os.Getenv("S3_BUCKET")
|
|
|
|
encrypt := os.Getenv("S3_ENCRYPT")
|
|
|
|
|
|
|
|
s3DriverConstructor := func() (storagedriver.StorageDriver, error) {
|
2014-10-29 02:15:40 +01:00
|
|
|
shouldEncrypt, err := strconv.ParseBool(encrypt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return New(accessKey, secretKey, aws.GetRegion(region), shouldEncrypt, bucket)
|
2014-10-25 01:37:25 +02:00
|
|
|
}
|
|
|
|
|
2014-10-29 02:15:40 +01:00
|
|
|
// Skip S3 storage driver tests if environment variable parameters are not provided
|
2014-10-27 21:24:07 +01:00
|
|
|
skipCheck := func() string {
|
|
|
|
if accessKey == "" || secretKey == "" || region == "" || bucket == "" || encrypt == "" {
|
2014-10-29 02:15:40 +01:00
|
|
|
return "Must set AWS_ACCESS_KEY, AWS_SECRET_KEY, AWS_REGION, S3_BUCKET, and S3_ENCRYPT to run S3 tests"
|
2014-10-27 21:24:07 +01:00
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
testsuites.RegisterInProcessSuite(s3DriverConstructor, skipCheck)
|
2014-10-29 02:15:40 +01:00
|
|
|
testsuites.RegisterIPCSuite(DriverName, map[string]string{
|
|
|
|
"accesskey": accessKey,
|
|
|
|
"secretkey": secretKey,
|
|
|
|
"region": region,
|
|
|
|
"bucket": bucket,
|
|
|
|
"encrypt": encrypt,
|
|
|
|
}, skipCheck)
|
2014-10-25 01:37:25 +02:00
|
|
|
}
|