Add an empty root directory s3 driver specific test
This commit is contained in:
parent
3e906311c6
commit
02718ee277
1 changed files with 64 additions and 11 deletions
|
@ -16,6 +16,8 @@ import (
|
||||||
// Hook up gocheck into the "go test" runner.
|
// Hook up gocheck into the "go test" runner.
|
||||||
func Test(t *testing.T) { check.TestingT(t) }
|
func Test(t *testing.T) { check.TestingT(t) }
|
||||||
|
|
||||||
|
type S3DriverConstructor func(rootDirectory string) (*Driver, error)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
accessKey := os.Getenv("AWS_ACCESS_KEY")
|
accessKey := os.Getenv("AWS_ACCESS_KEY")
|
||||||
secretKey := os.Getenv("AWS_SECRET_KEY")
|
secretKey := os.Getenv("AWS_SECRET_KEY")
|
||||||
|
@ -30,7 +32,7 @@ func init() {
|
||||||
}
|
}
|
||||||
defer os.Remove(root)
|
defer os.Remove(root)
|
||||||
|
|
||||||
s3DriverConstructor := func(region aws.Region) (storagedriver.StorageDriver, error) {
|
s3DriverConstructor := func(rootDirectory string) (*Driver, error) {
|
||||||
encryptBool := false
|
encryptBool := false
|
||||||
if encrypt != "" {
|
if encrypt != "" {
|
||||||
encryptBool, err = strconv.ParseBool(encrypt)
|
encryptBool, err = strconv.ParseBool(encrypt)
|
||||||
|
@ -47,7 +49,7 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v4AuthBool := true
|
v4AuthBool := false
|
||||||
if v4auth != "" {
|
if v4auth != "" {
|
||||||
v4AuthBool, err = strconv.ParseBool(v4auth)
|
v4AuthBool, err = strconv.ParseBool(v4auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -59,12 +61,12 @@ func init() {
|
||||||
accessKey,
|
accessKey,
|
||||||
secretKey,
|
secretKey,
|
||||||
bucket,
|
bucket,
|
||||||
region,
|
aws.GetRegion(region),
|
||||||
encryptBool,
|
encryptBool,
|
||||||
secureBool,
|
secureBool,
|
||||||
v4AuthBool,
|
v4AuthBool,
|
||||||
minChunkSize,
|
minChunkSize,
|
||||||
root,
|
rootDirectory,
|
||||||
}
|
}
|
||||||
|
|
||||||
return New(parameters)
|
return New(parameters)
|
||||||
|
@ -78,14 +80,18 @@ func init() {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// for _, region := range aws.Regions {
|
driverConstructor := func() (storagedriver.StorageDriver, error) {
|
||||||
// if region == aws.USGovWest {
|
return s3DriverConstructor(root)
|
||||||
// continue
|
}
|
||||||
// }
|
|
||||||
|
testsuites.RegisterInProcessSuite(driverConstructor, skipCheck)
|
||||||
|
|
||||||
|
// s3Constructor := func() (*Driver, error) {
|
||||||
|
// return s3DriverConstructor(aws.GetRegion(region))
|
||||||
|
// }
|
||||||
|
|
||||||
|
RegisterS3DriverSuite(s3DriverConstructor, skipCheck)
|
||||||
|
|
||||||
testsuites.RegisterInProcessSuite(func() (storagedriver.StorageDriver, error) {
|
|
||||||
return s3DriverConstructor(aws.GetRegion(region))
|
|
||||||
}, skipCheck)
|
|
||||||
// testsuites.RegisterIPCSuite(driverName, map[string]string{
|
// testsuites.RegisterIPCSuite(driverName, map[string]string{
|
||||||
// "accesskey": accessKey,
|
// "accesskey": accessKey,
|
||||||
// "secretkey": secretKey,
|
// "secretkey": secretKey,
|
||||||
|
@ -95,3 +101,50 @@ func init() {
|
||||||
// }, skipCheck)
|
// }, skipCheck)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RegisterS3DriverSuite(s3DriverConstructor S3DriverConstructor, skipCheck testsuites.SkipCheck) {
|
||||||
|
check.Suite(&S3DriverSuite{
|
||||||
|
Constructor: s3DriverConstructor,
|
||||||
|
SkipCheck: skipCheck,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type S3DriverSuite struct {
|
||||||
|
Constructor S3DriverConstructor
|
||||||
|
testsuites.SkipCheck
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *S3DriverSuite) SetUpSuite(c *check.C) {
|
||||||
|
if reason := suite.SkipCheck(); reason != "" {
|
||||||
|
c.Skip(reason)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *S3DriverSuite) TestEmptyRootList(c *check.C) {
|
||||||
|
validRoot, err := ioutil.TempDir("", "driver-")
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
defer os.Remove(validRoot)
|
||||||
|
|
||||||
|
rootedDriver, err := suite.Constructor(validRoot)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
emptyRootDriver, err := suite.Constructor("")
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
slashRootDriver, err := suite.Constructor("/")
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
|
filename := "/test"
|
||||||
|
contents := []byte("contents")
|
||||||
|
err = rootedDriver.PutContent(filename, contents)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
defer rootedDriver.Delete(filename)
|
||||||
|
|
||||||
|
keys, err := emptyRootDriver.List("/")
|
||||||
|
for _, path := range keys {
|
||||||
|
c.Assert(storagedriver.PathRegexp.MatchString(path), check.Equals, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
keys, err = slashRootDriver.List("/")
|
||||||
|
for _, path := range keys {
|
||||||
|
c.Assert(storagedriver.PathRegexp.MatchString(path), check.Equals, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue