From eaa717b88aec33613e6cfc1018a46ffcfe8e518a Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 18 Jun 2017 22:53:19 +0100 Subject: [PATCH] Fix crypt obfuscate tests with Windows --- crypt/crypt_config_test.go | 1 + fstest/fstests/fstests.go | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/crypt/crypt_config_test.go b/crypt/crypt_config_test.go index 954ab9f31..3cbe82996 100644 --- a/crypt/crypt_config_test.go +++ b/crypt/crypt_config_test.go @@ -30,4 +30,5 @@ func init() { {Name: name3, Key: "password", Value: fs.MustObscure("potato2")}, {Name: name3, Key: "filename_encryption", Value: "obfuscate"}, } + fstests.SkipBadWindowsCharacters[name3+":"] = true } diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go index fd996e89d..75b49f2b2 100644 --- a/fstest/fstests/fstests.go +++ b/fstest/fstests/fstests.go @@ -35,7 +35,9 @@ var ( NilObject fs.Object // ExtraConfig is for adding config to a remote ExtraConfig = []ExtraConfigItem{} - file1 = fstest.Item{ + // SkipBadWindowsCharacters skips unusable characters for windows if set + SkipBadWindowsCharacters = map[string]bool{} + file1 = fstest.Item{ ModTime: fstest.Time("2001-02-03T04:05:06.499999999Z"), Path: "file name.txt", } @@ -59,6 +61,12 @@ type ExtraConfigItem struct{ Name, Key, Value string } func TestInit(t *testing.T) { var err error + // Remove bad characters from Windows file name if set + if SkipBadWindowsCharacters[RemoteName] { + t.Logf("Removing bad windows characters from test file") + file2.Path = winPath(file2.Path) + } + // Never ask for passwords, fail instead. // If your local config is encrypted set environment variable // "RCLONE_CONFIG_PASS=hunter2" (or your password) @@ -165,11 +173,13 @@ func TestFsListEmpty(t *testing.T) { // winPath converts a path into a windows safe path func winPath(s string) string { - s = strings.Replace(s, "?", "_", -1) - s = strings.Replace(s, `"`, "_", -1) - s = strings.Replace(s, "<", "_", -1) - s = strings.Replace(s, ">", "_", -1) - return s + return strings.Map(func(r rune) rune { + switch r { + case '<', '>', '"', '|', '?', '*', ':': + return '_' + } + return r + }, s) } // dirsToNames returns a sorted list of names @@ -323,9 +333,9 @@ func TestFsListDirFile2(t *testing.T) { list := func(dir string, expectedDirNames, expectedObjNames []string) { var objNames, dirNames []string for i := 1; i <= *fstest.ListRetries; i++ { - objs, dirs, err := fs.WalkGetAll(remote, dir, false, 1) - if err == fs.ErrorDirNotFound { - objs, dirs, err = fs.WalkGetAll(remote, winPath(dir), false, 1) + objs, dirs, err := fs.WalkGetAll(remote, dir, true, 1) + if errors.Cause(err) == fs.ErrorDirNotFound { + objs, dirs, err = fs.WalkGetAll(remote, winPath(dir), true, 1) } require.NoError(t, err) objNames = objsToNames(objs)