Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fstest: fix CheckListingWithPrecision with non Windows safe chars

Nick Craig-Wood29ce1c2747f6
diff --git a/fstest/fstest.go b/fstest/fstest.go
index 11b5d5d98..c9cb7d871 100644
--- a/fstest/fstest.go
+++ b/fstest/fstest.go
@@ -140,6 +140,17 @@ func (i *Item) Check(t *testing.T, obj fs.Object, precision time.Duration) {
i.CheckModTime(t, obj, obj.ModTime(), precision)
}
+// WinPath converts a path into a windows safe path
+func WinPath(s string) string {
+ return strings.Map(func(r rune) rune {
+ switch r {
+ case '<', '>', '"', '|', '?', '*', ':':
+ return '_'
+ }
+ return r
+ }, s)
+}
+
// Normalize runs a utf8 normalization on the string if running on OS
// X. This is because OS X denormalizes file names it writes to the
// local file system.
@@ -311,11 +322,11 @@ func CheckListingWithPrecision(t *testing.T, f fs.Fs, items []Item, expectedDirs
if expectedDirs != nil {
expectedDirsCopy := make([]string, len(expectedDirs))
for i, dir := range expectedDirs {
- expectedDirsCopy[i] = Normalize(dir)
+ expectedDirsCopy[i] = WinPath(Normalize(dir))
}
actualDirs := []string{}
for _, dir := range dirs {
- actualDirs = append(actualDirs, Normalize(dir.Remote()))
+ actualDirs = append(actualDirs, WinPath(Normalize(dir.Remote())))
}
sort.Strings(actualDirs)
sort.Strings(expectedDirsCopy)
diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go
index 193f17ecb..bdf9b326a 100644
--- a/fstest/fstests/fstests.go
+++ b/fstest/fstests/fstests.go
@@ -35,22 +35,11 @@ type InternalTester interface {
InternalTest(*testing.T)
}
-// winPath converts a path into a windows safe path
-func winPath(s string) string {
- return strings.Map(func(r rune) rune {
- switch r {
- case '<', '>', '"', '|', '?', '*', ':':
- return '_'
- }
- return r
- }, s)
-}
-
// dirsToNames returns a sorted list of names
func dirsToNames(dirs []fs.Directory) []string {
names := []string{}
for _, dir := range dirs {
- names = append(names, winPath(fstest.Normalize(dir.Remote())))
+ names = append(names, fstest.WinPath(fstest.Normalize(dir.Remote())))
}
sort.Strings(names)
return names
@@ -60,7 +49,7 @@ func dirsToNames(dirs []fs.Directory) []string {
func objsToNames(objs []fs.Object) []string {
names := []string{}
for _, obj := range objs {
- names = append(names, winPath(fstest.Normalize(obj.Remote())))
+ names = append(names, fstest.WinPath(fstest.Normalize(obj.Remote())))
}
sort.Strings(names)
return names
@@ -217,7 +206,7 @@ func Run(t *testing.T, opt *Opt) {
// Remove bad characters from Windows file name if set
if opt.SkipBadWindowsCharacters {
t.Logf("Removing bad windows characters from test file")
- file2.Path = winPath(file2.Path)
+ file2.Path = fstest.WinPath(file2.Path)
}
fstest.Initialise()
@@ -410,7 +399,7 @@ func Run(t *testing.T, opt *Opt) {
for i := 1; i <= *fstest.ListRetries; i++ {
objs, dirs, err := walk.GetAll(remote, dir, true, 1)
if errors.Cause(err) == fs.ErrorDirNotFound {
- objs, dirs, err = walk.GetAll(remote, winPath(dir), true, 1)
+ objs, dirs, err = walk.GetAll(remote, fstest.WinPath(dir), true, 1)
}
require.NoError(t, err)
objNames = objsToNames(objs)
@@ -433,13 +422,13 @@ func Run(t *testing.T, opt *Opt) {
dir = path.Dir(dir)
if dir == "." {
dir = ""
- expectedObjNames = append(expectedObjNames, winPath(file1.Path))
+ expectedObjNames = append(expectedObjNames, fstest.WinPath(file1.Path))
}
if deepest {
- expectedObjNames = append(expectedObjNames, winPath(file2.Path))
+ expectedObjNames = append(expectedObjNames, fstest.WinPath(file2.Path))
deepest = false
} else {
- expectedDirNames = append(expectedDirNames, winPath(child))
+ expectedDirNames = append(expectedDirNames, fstest.WinPath(child))
}
list(dir, expectedDirNames, expectedObjNames)
}