From e6a0521ca2bbd1489ae632b3a2a61ade1c89aee0 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 20 Aug 2016 18:47:33 +0100 Subject: [PATCH] Make it possible to test Fs multiple times and use this with crypt We test both the filename encryption modes for crypt. --- amazonclouddrive/amazonclouddrive_test.go | 2 +- b2/b2_test.go | 2 +- crypt/crypt2_test.go | 59 +++++++++++++++++++ crypt/crypt_config_test.go | 9 ++- crypt/crypt_test.go | 2 +- drive/drive_test.go | 2 +- dropbox/dropbox_test.go | 2 +- fstest/fstests/gen_tests.go | 37 ++++++------ googlecloudstorage/googlecloudstorage_test.go | 2 +- hubic/hubic_test.go | 2 +- local/local_test.go | 2 +- onedrive/onedrive_test.go | 2 +- s3/s3_test.go | 2 +- swift/swift_test.go | 2 +- yandex/yandex_test.go | 2 +- 15 files changed, 99 insertions(+), 30 deletions(-) create mode 100644 crypt/crypt2_test.go diff --git a/amazonclouddrive/amazonclouddrive_test.go b/amazonclouddrive/amazonclouddrive_test.go index 07187f0d2..39d4d9c41 100644 --- a/amazonclouddrive/amazonclouddrive_test.go +++ b/amazonclouddrive/amazonclouddrive_test.go @@ -12,7 +12,7 @@ import ( "github.com/ncw/rclone/fstest/fstests" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*amazonclouddrive.Object)(nil)) fstests.RemoteName = "TestAmazonCloudDrive:" } diff --git a/b2/b2_test.go b/b2/b2_test.go index 510541d04..64c45533a 100644 --- a/b2/b2_test.go +++ b/b2/b2_test.go @@ -12,7 +12,7 @@ import ( "github.com/ncw/rclone/fstest/fstests" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*b2.Object)(nil)) fstests.RemoteName = "TestB2:" } diff --git a/crypt/crypt2_test.go b/crypt/crypt2_test.go new file mode 100644 index 000000000..9fd7db801 --- /dev/null +++ b/crypt/crypt2_test.go @@ -0,0 +1,59 @@ +// Test Crypt filesystem interface +// +// Automatically generated - DO NOT EDIT +// Regenerate with: make gen_tests +package crypt_test + +import ( + "testing" + + "github.com/ncw/rclone/crypt" + "github.com/ncw/rclone/fs" + "github.com/ncw/rclone/fstest/fstests" + _ "github.com/ncw/rclone/local" +) + +func TestSetup2(t *testing.T) { + fstests.NilObject = fs.Object((*crypt.Object)(nil)) + fstests.RemoteName = "TestCrypt2:" +} + +// Generic tests for the Fs +func TestInit2(t *testing.T) { fstests.TestInit(t) } +func TestFsString2(t *testing.T) { fstests.TestFsString(t) } +func TestFsRmdirEmpty2(t *testing.T) { fstests.TestFsRmdirEmpty(t) } +func TestFsRmdirNotFound2(t *testing.T) { fstests.TestFsRmdirNotFound(t) } +func TestFsMkdir2(t *testing.T) { fstests.TestFsMkdir(t) } +func TestFsListEmpty2(t *testing.T) { fstests.TestFsListEmpty(t) } +func TestFsListDirEmpty2(t *testing.T) { fstests.TestFsListDirEmpty(t) } +func TestFsNewObjectNotFound2(t *testing.T) { fstests.TestFsNewObjectNotFound(t) } +func TestFsPutFile12(t *testing.T) { fstests.TestFsPutFile1(t) } +func TestFsPutFile22(t *testing.T) { fstests.TestFsPutFile2(t) } +func TestFsUpdateFile12(t *testing.T) { fstests.TestFsUpdateFile1(t) } +func TestFsListDirFile22(t *testing.T) { fstests.TestFsListDirFile2(t) } +func TestFsListDirRoot2(t *testing.T) { fstests.TestFsListDirRoot(t) } +func TestFsListSubdir2(t *testing.T) { fstests.TestFsListSubdir(t) } +func TestFsListLevel22(t *testing.T) { fstests.TestFsListLevel2(t) } +func TestFsListFile12(t *testing.T) { fstests.TestFsListFile1(t) } +func TestFsNewObject2(t *testing.T) { fstests.TestFsNewObject(t) } +func TestFsListFile1and22(t *testing.T) { fstests.TestFsListFile1and2(t) } +func TestFsCopy2(t *testing.T) { fstests.TestFsCopy(t) } +func TestFsMove2(t *testing.T) { fstests.TestFsMove(t) } +func TestFsDirMove2(t *testing.T) { fstests.TestFsDirMove(t) } +func TestFsRmdirFull2(t *testing.T) { fstests.TestFsRmdirFull(t) } +func TestFsPrecision2(t *testing.T) { fstests.TestFsPrecision(t) } +func TestObjectString2(t *testing.T) { fstests.TestObjectString(t) } +func TestObjectFs2(t *testing.T) { fstests.TestObjectFs(t) } +func TestObjectRemote2(t *testing.T) { fstests.TestObjectRemote(t) } +func TestObjectHashes2(t *testing.T) { fstests.TestObjectHashes(t) } +func TestObjectModTime2(t *testing.T) { fstests.TestObjectModTime(t) } +func TestObjectSetModTime2(t *testing.T) { fstests.TestObjectSetModTime(t) } +func TestObjectSize2(t *testing.T) { fstests.TestObjectSize(t) } +func TestObjectOpen2(t *testing.T) { fstests.TestObjectOpen(t) } +func TestObjectUpdate2(t *testing.T) { fstests.TestObjectUpdate(t) } +func TestObjectStorable2(t *testing.T) { fstests.TestObjectStorable(t) } +func TestFsIsFile2(t *testing.T) { fstests.TestFsIsFile(t) } +func TestFsIsFileNotFound2(t *testing.T) { fstests.TestFsIsFileNotFound(t) } +func TestObjectRemove2(t *testing.T) { fstests.TestObjectRemove(t) } +func TestObjectPurge2(t *testing.T) { fstests.TestObjectPurge(t) } +func TestFinalise2(t *testing.T) { fstests.TestFinalise(t) } diff --git a/crypt/crypt_config_test.go b/crypt/crypt_config_test.go index d9961cf28..0b3ecedde 100644 --- a/crypt/crypt_config_test.go +++ b/crypt/crypt_config_test.go @@ -10,11 +10,18 @@ import ( // Create the TestCrypt: remote func init() { - tempdir := filepath.Join(os.TempDir(), "rclone-crypt-test") + tempdir := filepath.Join(os.TempDir(), "rclone-crypt-test-standard") name := "TestCrypt" + tempdir2 := filepath.Join(os.TempDir(), "rclone-crypt-test-off") + name2 := name + "2" fstests.ExtraConfig = []fstests.ExtraConfigItem{ {Name: name, Key: "type", Value: "crypt"}, {Name: name, Key: "remote", Value: tempdir}, {Name: name, Key: "password", Value: fs.MustObscure("potato")}, + {Name: name, Key: "filename_encryption", Value: "standard"}, + {Name: name2, Key: "type", Value: "crypt"}, + {Name: name2, Key: "remote", Value: tempdir2}, + {Name: name2, Key: "password", Value: fs.MustObscure("potato2")}, + {Name: name2, Key: "filename_encryption", Value: "off"}, } } diff --git a/crypt/crypt_test.go b/crypt/crypt_test.go index 8f73f5543..f994fa918 100644 --- a/crypt/crypt_test.go +++ b/crypt/crypt_test.go @@ -13,7 +13,7 @@ import ( _ "github.com/ncw/rclone/local" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*crypt.Object)(nil)) fstests.RemoteName = "TestCrypt:" } diff --git a/drive/drive_test.go b/drive/drive_test.go index 08c609837..657a78a1e 100644 --- a/drive/drive_test.go +++ b/drive/drive_test.go @@ -12,7 +12,7 @@ import ( "github.com/ncw/rclone/fstest/fstests" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*drive.Object)(nil)) fstests.RemoteName = "TestDrive:" } diff --git a/dropbox/dropbox_test.go b/dropbox/dropbox_test.go index c65248951..59c68e659 100644 --- a/dropbox/dropbox_test.go +++ b/dropbox/dropbox_test.go @@ -12,7 +12,7 @@ import ( "github.com/ncw/rclone/fstest/fstests" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*dropbox.Object)(nil)) fstests.RemoteName = "TestDropbox:" } diff --git a/fstest/fstests/gen_tests.go b/fstest/fstests/gen_tests.go index 366fe56cd..d2ac92eb9 100644 --- a/fstest/fstests/gen_tests.go +++ b/fstest/fstests/gen_tests.go @@ -46,6 +46,7 @@ type Data struct { UpperFsName string TestName string Fns []string + Suffix string } var testProgram = ` @@ -64,21 +65,21 @@ import ( {{ if eq .FsName "crypt" }} _ "github.com/ncw/rclone/local" {{end}}) -func init() { +func TestSetup{{ .Suffix }}(t *testing.T)() { fstests.NilObject = fs.Object((*{{ .FsName }}.Object)(nil)) fstests.RemoteName = "{{ .TestName }}" } // Generic tests for the Fs -{{ range $fn := .Fns }}func {{ $fn }}(t *testing.T){ fstests.{{ $fn }}(t) } +{{ range $fn := .Fns }}func {{ $fn }}{{ $.Suffix }}(t *testing.T){ fstests.{{ $fn }}(t) } {{ end }} ` // Generate test file piping it through gofmt -func generateTestProgram(t *template.Template, fns []string, Fsname string) { +func generateTestProgram(t *template.Template, fns []string, Fsname string, suffix string) { fsname := strings.ToLower(Fsname) - TestName := "Test" + Fsname + ":" - outfile := "../../" + fsname + "/" + fsname + "_test.go" + TestName := "Test" + Fsname + suffix + ":" + outfile := "../../" + fsname + "/" + fsname + suffix + "_test.go" if fsname == "local" { TestName = "" @@ -90,6 +91,7 @@ func generateTestProgram(t *template.Template, fns []string, Fsname string) { UpperFsName: Fsname, TestName: TestName, Fns: fns, + Suffix: suffix, } cmd := exec.Command("gofmt") @@ -125,17 +127,18 @@ func generateTestProgram(t *template.Template, fns []string, Fsname string) { func main() { fns := findTestFunctions() t := template.Must(template.New("main").Parse(testProgram)) - generateTestProgram(t, fns, "Local") - generateTestProgram(t, fns, "Swift") - generateTestProgram(t, fns, "S3") - generateTestProgram(t, fns, "Drive") - generateTestProgram(t, fns, "GoogleCloudStorage") - generateTestProgram(t, fns, "Dropbox") - generateTestProgram(t, fns, "AmazonCloudDrive") - generateTestProgram(t, fns, "OneDrive") - generateTestProgram(t, fns, "Hubic") - generateTestProgram(t, fns, "B2") - generateTestProgram(t, fns, "Yandex") - generateTestProgram(t, fns, "Crypt") + generateTestProgram(t, fns, "Local", "") + generateTestProgram(t, fns, "Swift", "") + generateTestProgram(t, fns, "S3", "") + generateTestProgram(t, fns, "Drive", "") + generateTestProgram(t, fns, "GoogleCloudStorage", "") + generateTestProgram(t, fns, "Dropbox", "") + generateTestProgram(t, fns, "AmazonCloudDrive", "") + generateTestProgram(t, fns, "OneDrive", "") + generateTestProgram(t, fns, "Hubic", "") + generateTestProgram(t, fns, "B2", "") + generateTestProgram(t, fns, "Yandex", "") + generateTestProgram(t, fns, "Crypt", "") + generateTestProgram(t, fns, "Crypt", "2") log.Printf("Done") } diff --git a/googlecloudstorage/googlecloudstorage_test.go b/googlecloudstorage/googlecloudstorage_test.go index a32bed947..208435376 100644 --- a/googlecloudstorage/googlecloudstorage_test.go +++ b/googlecloudstorage/googlecloudstorage_test.go @@ -12,7 +12,7 @@ import ( "github.com/ncw/rclone/googlecloudstorage" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*googlecloudstorage.Object)(nil)) fstests.RemoteName = "TestGoogleCloudStorage:" } diff --git a/hubic/hubic_test.go b/hubic/hubic_test.go index 085319e36..46eda5725 100644 --- a/hubic/hubic_test.go +++ b/hubic/hubic_test.go @@ -12,7 +12,7 @@ import ( "github.com/ncw/rclone/hubic" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*hubic.Object)(nil)) fstests.RemoteName = "TestHubic:" } diff --git a/local/local_test.go b/local/local_test.go index 51455b0c2..4619032cc 100644 --- a/local/local_test.go +++ b/local/local_test.go @@ -12,7 +12,7 @@ import ( "github.com/ncw/rclone/local" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*local.Object)(nil)) fstests.RemoteName = "" } diff --git a/onedrive/onedrive_test.go b/onedrive/onedrive_test.go index bd6a2d1d3..e8e230056 100644 --- a/onedrive/onedrive_test.go +++ b/onedrive/onedrive_test.go @@ -12,7 +12,7 @@ import ( "github.com/ncw/rclone/onedrive" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*onedrive.Object)(nil)) fstests.RemoteName = "TestOneDrive:" } diff --git a/s3/s3_test.go b/s3/s3_test.go index e6fc666db..5bde96ae9 100644 --- a/s3/s3_test.go +++ b/s3/s3_test.go @@ -12,7 +12,7 @@ import ( "github.com/ncw/rclone/s3" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*s3.Object)(nil)) fstests.RemoteName = "TestS3:" } diff --git a/swift/swift_test.go b/swift/swift_test.go index 9bc80ee7a..941c6e7b3 100644 --- a/swift/swift_test.go +++ b/swift/swift_test.go @@ -12,7 +12,7 @@ import ( "github.com/ncw/rclone/swift" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*swift.Object)(nil)) fstests.RemoteName = "TestSwift:" } diff --git a/yandex/yandex_test.go b/yandex/yandex_test.go index 574b8def7..23ef7a2a0 100644 --- a/yandex/yandex_test.go +++ b/yandex/yandex_test.go @@ -12,7 +12,7 @@ import ( "github.com/ncw/rclone/yandex" ) -func init() { +func TestSetup(t *testing.T) { fstests.NilObject = fs.Object((*yandex.Object)(nil)) fstests.RemoteName = "TestYandex:" }