Make it possible to test Fs multiple times and use this with crypt

We test both the filename encryption modes for crypt.
This commit is contained in:
Nick Craig-Wood 2016-08-20 18:47:33 +01:00
parent 43eadf278c
commit e6a0521ca2
15 changed files with 99 additions and 30 deletions

View File

@ -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:"
}

View File

@ -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:"
}

59
crypt/crypt2_test.go Normal file
View File

@ -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) }

View File

@ -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"},
}
}

View File

@ -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:"
}

View File

@ -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:"
}

View File

@ -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:"
}

View File

@ -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")
}

View File

@ -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:"
}

View File

@ -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:"
}

View File

@ -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 = ""
}

View File

@ -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:"
}

View File

@ -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:"
}

View File

@ -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:"
}

View File

@ -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:"
}