Adds conditional SkipCheck for storage driver tests

This commit is contained in:
Brian Bland 2014-10-27 13:24:07 -07:00
parent bac40b2b35
commit ff81f3a719
4 changed files with 30 additions and 9 deletions

View file

@ -19,6 +19,6 @@ func init() {
filesystemDriverConstructor := func() (storagedriver.StorageDriver, error) {
return NewDriver(rootDirectory), nil
}
testsuites.RegisterInProcessSuite(filesystemDriverConstructor)
testsuites.RegisterIPCSuite("filesystem", map[string]string{"RootDirectory": rootDirectory})
testsuites.RegisterInProcessSuite(filesystemDriverConstructor, testsuites.NeverSkip)
testsuites.RegisterIPCSuite("filesystem", map[string]string{"RootDirectory": rootDirectory}, testsuites.NeverSkip)
}

View file

@ -15,6 +15,6 @@ func init() {
inmemoryDriverConstructor := func() (storagedriver.StorageDriver, error) {
return NewDriver(), nil
}
testsuites.RegisterInProcessSuite(inmemoryDriverConstructor)
testsuites.RegisterIPCSuite("inmemory", nil)
testsuites.RegisterInProcessSuite(inmemoryDriverConstructor, testsuites.NeverSkip)
testsuites.RegisterIPCSuite("inmemory", nil, testsuites.NeverSkip)
}

View file

@ -24,6 +24,13 @@ func init() {
return NewDriver(accessKey, secretKey, aws.GetRegion(region), true, bucket)
}
testsuites.RegisterInProcessSuite(s3DriverConstructor)
testsuites.RegisterIPCSuite("s3", map[string]string{"accessKey": accessKey, "secretKey": secretKey, "region": region, "bucket": bucket, "encrypt": encrypt})
skipCheck := func() string {
if accessKey == "" || secretKey == "" || region == "" || bucket == "" || encrypt == "" {
return "Must set ACCESS_KEY, SECRET_KEY, AWS_REGION, S3_BUCKET, and S3_ENCRYPT to run S3 tests"
}
return ""
}
testsuites.RegisterInProcessSuite(s3DriverConstructor, skipCheck)
testsuites.RegisterIPCSuite("s3", map[string]string{"accessKey": accessKey, "secretKey": secretKey, "region": region, "bucket": bucket, "encrypt": encrypt}, skipCheck)
}

View file

@ -17,13 +17,14 @@ import (
// Hook up gocheck into the "go test" runner
func Test(t *testing.T) { TestingT(t) }
func RegisterInProcessSuite(driverConstructor DriverConstructor) {
func RegisterInProcessSuite(driverConstructor DriverConstructor, skipCheck SkipCheck) {
Suite(&DriverSuite{
Constructor: driverConstructor,
SkipCheck: skipCheck,
})
}
func RegisterIPCSuite(driverName string, ipcParams map[string]string) {
func RegisterIPCSuite(driverName string, ipcParams map[string]string, skipCheck SkipCheck) {
suite := &DriverSuite{
Constructor: func() (storagedriver.StorageDriver, error) {
d, err := ipc.NewDriverClient(driverName, ipcParams)
@ -36,20 +37,30 @@ func RegisterIPCSuite(driverName string, ipcParams map[string]string) {
}
return d, nil
},
SkipCheck: skipCheck,
}
suite.Teardown = func() error {
if suite.StorageDriver == nil {
return nil
}
driverClient := suite.StorageDriver.(*ipc.StorageDriverClient)
return driverClient.Stop()
}
Suite(suite)
}
type SkipCheck func() (reason string)
var NeverSkip = func() string { return "" }
type DriverConstructor func() (storagedriver.StorageDriver, error)
type DriverTeardown func() error
type DriverSuite struct {
Constructor DriverConstructor
Teardown DriverTeardown
SkipCheck
storagedriver.StorageDriver
}
@ -59,6 +70,9 @@ type TestDriverConfig struct {
}
func (suite *DriverSuite) SetUpSuite(c *C) {
if reason := suite.SkipCheck(); reason != "" {
c.Skip(reason)
}
d, err := suite.Constructor()
c.Assert(err, IsNil)
suite.StorageDriver = d
@ -129,7 +143,7 @@ func (suite *DriverSuite) TestContinueStreamAppend(c *C) {
filename := randomString(32)
defer suite.StorageDriver.Delete(filename)
chunkSize := uint64(5 * 1024 * 1024)
chunkSize := uint64(10 * 1024 * 1024)
contentsChunk1 := []byte(randomString(chunkSize))
contentsChunk2 := []byte(randomString(chunkSize))