1
mirror of https://github.com/rclone/rclone synced 2025-01-03 03:46:24 +01:00

Fix crypt obfuscate tests with Windows

This commit is contained in:
Nick Craig-Wood 2017-06-18 22:53:19 +01:00
parent bbbc202ee6
commit eaa717b88a
2 changed files with 20 additions and 9 deletions

View File

@ -30,4 +30,5 @@ func init() {
{Name: name3, Key: "password", Value: fs.MustObscure("potato2")}, {Name: name3, Key: "password", Value: fs.MustObscure("potato2")},
{Name: name3, Key: "filename_encryption", Value: "obfuscate"}, {Name: name3, Key: "filename_encryption", Value: "obfuscate"},
} }
fstests.SkipBadWindowsCharacters[name3+":"] = true
} }

View File

@ -35,6 +35,8 @@ var (
NilObject fs.Object NilObject fs.Object
// ExtraConfig is for adding config to a remote // ExtraConfig is for adding config to a remote
ExtraConfig = []ExtraConfigItem{} ExtraConfig = []ExtraConfigItem{}
// SkipBadWindowsCharacters skips unusable characters for windows if set
SkipBadWindowsCharacters = map[string]bool{}
file1 = fstest.Item{ file1 = fstest.Item{
ModTime: fstest.Time("2001-02-03T04:05:06.499999999Z"), ModTime: fstest.Time("2001-02-03T04:05:06.499999999Z"),
Path: "file name.txt", Path: "file name.txt",
@ -59,6 +61,12 @@ type ExtraConfigItem struct{ Name, Key, Value string }
func TestInit(t *testing.T) { func TestInit(t *testing.T) {
var err error 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. // Never ask for passwords, fail instead.
// If your local config is encrypted set environment variable // If your local config is encrypted set environment variable
// "RCLONE_CONFIG_PASS=hunter2" (or your password) // "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 // winPath converts a path into a windows safe path
func winPath(s string) string { func winPath(s string) string {
s = strings.Replace(s, "?", "_", -1) return strings.Map(func(r rune) rune {
s = strings.Replace(s, `"`, "_", -1) switch r {
s = strings.Replace(s, "<", "_", -1) case '<', '>', '"', '|', '?', '*', ':':
s = strings.Replace(s, ">", "_", -1) return '_'
return s }
return r
}, s)
} }
// dirsToNames returns a sorted list of names // dirsToNames returns a sorted list of names
@ -323,9 +333,9 @@ func TestFsListDirFile2(t *testing.T) {
list := func(dir string, expectedDirNames, expectedObjNames []string) { list := func(dir string, expectedDirNames, expectedObjNames []string) {
var objNames, dirNames []string var objNames, dirNames []string
for i := 1; i <= *fstest.ListRetries; i++ { for i := 1; i <= *fstest.ListRetries; i++ {
objs, dirs, err := fs.WalkGetAll(remote, dir, false, 1) objs, dirs, err := fs.WalkGetAll(remote, dir, true, 1)
if err == fs.ErrorDirNotFound { if errors.Cause(err) == fs.ErrorDirNotFound {
objs, dirs, err = fs.WalkGetAll(remote, winPath(dir), false, 1) objs, dirs, err = fs.WalkGetAll(remote, winPath(dir), true, 1)
} }
require.NoError(t, err) require.NoError(t, err)
objNames = objsToNames(objs) objNames = objsToNames(objs)