Update the OSS test case for latest code change
Signed-off-by: Li Yi <denverdino@gmail.com>
This commit is contained in:
parent
fc20dd72d6
commit
440664a109
1 changed files with 38 additions and 51 deletions
|
@ -17,7 +17,9 @@ 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 OSSDriverConstructor func(rootDirectory string) (*Driver, error)
|
var ossDriverConstructor func(rootDirectory string) (*Driver, error)
|
||||||
|
|
||||||
|
var skipCheck func() string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
accessKey := os.Getenv("ALIYUN_ACCESS_KEY_ID")
|
accessKey := os.Getenv("ALIYUN_ACCESS_KEY_ID")
|
||||||
|
@ -34,7 +36,7 @@ func init() {
|
||||||
}
|
}
|
||||||
defer os.Remove(root)
|
defer os.Remove(root)
|
||||||
|
|
||||||
ossDriverConstructor := func(rootDirectory string) (*Driver, error) {
|
ossDriverConstructor = func(rootDirectory string) (*Driver, error) {
|
||||||
encryptBool := false
|
encryptBool := false
|
||||||
if encrypt != "" {
|
if encrypt != "" {
|
||||||
encryptBool, err = strconv.ParseBool(encrypt)
|
encryptBool, err = strconv.ParseBool(encrypt)
|
||||||
|
@ -76,79 +78,64 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip OSS storage driver tests if environment variable parameters are not provided
|
// Skip OSS storage driver tests if environment variable parameters are not provided
|
||||||
skipCheck := func() string {
|
skipCheck = func() string {
|
||||||
if accessKey == "" || secretKey == "" || region == "" || bucket == "" || encrypt == "" {
|
if accessKey == "" || secretKey == "" || region == "" || bucket == "" || encrypt == "" {
|
||||||
return "Must set ALIYUN_ACCESS_KEY_ID, ALIYUN_ACCESS_KEY_SECRET, OSS_REGION, OSS_BUCKET, and OSS_ENCRYPT to run OSS tests"
|
return "Must set ALIYUN_ACCESS_KEY_ID, ALIYUN_ACCESS_KEY_SECRET, OSS_REGION, OSS_BUCKET, and OSS_ENCRYPT to run OSS tests"
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
driverConstructor := func() (storagedriver.StorageDriver, error) {
|
testsuites.RegisterSuite(func() (storagedriver.StorageDriver, error) {
|
||||||
return ossDriverConstructor(root)
|
return ossDriverConstructor(root)
|
||||||
|
}, skipCheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
testsuites.RegisterInProcessSuite(driverConstructor, skipCheck)
|
func TestEmptyRootList(t *testing.T) {
|
||||||
|
if skipCheck() != "" {
|
||||||
// ossConstructor := func() (*Driver, error) {
|
t.Skip(skipCheck())
|
||||||
// return ossDriverConstructor(aws.GetRegion(region))
|
|
||||||
// }
|
|
||||||
|
|
||||||
RegisterOSSDriverSuite(ossDriverConstructor, skipCheck)
|
|
||||||
|
|
||||||
// testsuites.RegisterIPCSuite(driverName, map[string]string{
|
|
||||||
// "accesskey": accessKey,
|
|
||||||
// "secretkey": secretKey,
|
|
||||||
// "region": region.Name,
|
|
||||||
// "bucket": bucket,
|
|
||||||
// "encrypt": encrypt,
|
|
||||||
// }, skipCheck)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterOSSDriverSuite(ossDriverConstructor OSSDriverConstructor, skipCheck testsuites.SkipCheck) {
|
|
||||||
check.Suite(&OSSDriverSuite{
|
|
||||||
Constructor: ossDriverConstructor,
|
|
||||||
SkipCheck: skipCheck,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
type OSSDriverSuite struct {
|
|
||||||
Constructor OSSDriverConstructor
|
|
||||||
testsuites.SkipCheck
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *OSSDriverSuite) SetUpSuite(c *check.C) {
|
|
||||||
if reason := suite.SkipCheck(); reason != "" {
|
|
||||||
c.Skip(reason)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *OSSDriverSuite) TestEmptyRootList(c *check.C) {
|
|
||||||
validRoot, err := ioutil.TempDir("", "driver-")
|
validRoot, err := ioutil.TempDir("", "driver-")
|
||||||
c.Assert(err, check.IsNil)
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error creating temporary directory: %v", err)
|
||||||
|
}
|
||||||
defer os.Remove(validRoot)
|
defer os.Remove(validRoot)
|
||||||
|
|
||||||
rootedDriver, err := suite.Constructor(validRoot)
|
rootedDriver, err := ossDriverConstructor(validRoot)
|
||||||
c.Assert(err, check.IsNil)
|
if err != nil {
|
||||||
emptyRootDriver, err := suite.Constructor("")
|
t.Fatalf("unexpected error creating rooted driver: %v", err)
|
||||||
c.Assert(err, check.IsNil)
|
}
|
||||||
slashRootDriver, err := suite.Constructor("/")
|
|
||||||
c.Assert(err, check.IsNil)
|
emptyRootDriver, err := ossDriverConstructor("")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error creating empty root driver: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
slashRootDriver, err := ossDriverConstructor("/")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error creating slash root driver: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
filename := "/test"
|
filename := "/test"
|
||||||
contents := []byte("contents")
|
contents := []byte("contents")
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
err = rootedDriver.PutContent(ctx, filename, contents)
|
err = rootedDriver.PutContent(ctx, filename, contents)
|
||||||
c.Assert(err, check.IsNil)
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error creating content: %v", err)
|
||||||
|
}
|
||||||
defer rootedDriver.Delete(ctx, filename)
|
defer rootedDriver.Delete(ctx, filename)
|
||||||
|
|
||||||
keys, err := emptyRootDriver.List(ctx, "/")
|
keys, err := emptyRootDriver.List(ctx, "/")
|
||||||
for _, path := range keys {
|
for _, path := range keys {
|
||||||
c.Assert(storagedriver.PathRegexp.MatchString(path), check.Equals, true)
|
if !storagedriver.PathRegexp.MatchString(path) {
|
||||||
|
t.Fatalf("unexpected string in path: %q != %q", path, storagedriver.PathRegexp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keys, err = slashRootDriver.List(ctx, "/")
|
keys, err = slashRootDriver.List(ctx, "/")
|
||||||
for _, path := range keys {
|
for _, path := range keys {
|
||||||
c.Assert(storagedriver.PathRegexp.MatchString(path), check.Equals, true)
|
if !storagedriver.PathRegexp.MatchString(path) {
|
||||||
|
t.Fatalf("unexpected string in path: %q != %q", path, storagedriver.PathRegexp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue