fstest: remove WinPath as it is no longer needed

This commit is contained in:
Nick Craig-Wood 2019-08-26 20:22:38 +01:00
parent 7689bd7e21
commit 7e738c9d71
2 changed files with 20 additions and 37 deletions

View file

@ -142,17 +142,6 @@ func (i *Item) Check(t *testing.T, obj fs.Object, precision time.Duration) {
i.CheckModTime(t, obj, obj.ModTime(context.Background()), precision) i.CheckModTime(t, obj, obj.ModTime(context.Background()), 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 // 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 // X. This is because OS X denormalizes file names it writes to the
// local file system. // local file system.
@ -318,11 +307,11 @@ func CheckListingWithRoot(t *testing.T, f fs.Fs, dir string, items []Item, expec
if expectedDirs != nil { if expectedDirs != nil {
expectedDirsCopy := make([]string, len(expectedDirs)) expectedDirsCopy := make([]string, len(expectedDirs))
for i, dir := range expectedDirs { for i, dir := range expectedDirs {
expectedDirsCopy[i] = WinPath(Normalize(dir)) expectedDirsCopy[i] = Normalize(dir)
} }
actualDirs := []string{} actualDirs := []string{}
for _, dir := range dirs { for _, dir := range dirs {
actualDirs = append(actualDirs, WinPath(Normalize(dir.Remote()))) actualDirs = append(actualDirs, Normalize(dir.Remote()))
} }
sort.Strings(actualDirs) sort.Strings(actualDirs)
sort.Strings(expectedDirsCopy) sort.Strings(expectedDirsCopy)
@ -383,11 +372,11 @@ func CompareItems(t *testing.T, entries fs.DirEntries, items []Item, expectedDir
if expectedDirs != nil { if expectedDirs != nil {
expectedDirsCopy := make([]string, len(expectedDirs)) expectedDirsCopy := make([]string, len(expectedDirs))
for i, dir := range expectedDirs { for i, dir := range expectedDirs {
expectedDirsCopy[i] = WinPath(Normalize(dir)) expectedDirsCopy[i] = Normalize(dir)
} }
actualDirs := []string{} actualDirs := []string{}
for _, dir := range dirs { for _, dir := range dirs {
actualDirs = append(actualDirs, WinPath(Normalize(dir.Remote()))) actualDirs = append(actualDirs, Normalize(dir.Remote()))
} }
sort.Strings(actualDirs) sort.Strings(actualDirs)
sort.Strings(expectedDirsCopy) sort.Strings(expectedDirsCopy)

View file

@ -101,7 +101,7 @@ func NextMultipleOf(m fs.SizeSuffix) func(fs.SizeSuffix) fs.SizeSuffix {
func dirsToNames(dirs []fs.Directory) []string { func dirsToNames(dirs []fs.Directory) []string {
names := []string{} names := []string{}
for _, dir := range dirs { for _, dir := range dirs {
names = append(names, fstest.WinPath(fstest.Normalize(dir.Remote()))) names = append(names, fstest.Normalize(dir.Remote()))
} }
sort.Strings(names) sort.Strings(names)
return names return names
@ -111,7 +111,7 @@ func dirsToNames(dirs []fs.Directory) []string {
func objsToNames(objs []fs.Object) []string { func objsToNames(objs []fs.Object) []string {
names := []string{} names := []string{}
for _, obj := range objs { for _, obj := range objs {
names = append(names, fstest.WinPath(fstest.Normalize(obj.Remote()))) names = append(names, fstest.Normalize(obj.Remote()))
} }
sort.Strings(names) sort.Strings(names)
return names return names
@ -335,12 +335,6 @@ func Run(t *testing.T, opt *Opt) {
return fs.UnWrapFs(f).Features().BucketBased && strings.Contains(strings.Trim(f.Root(), "/"), "/") return fs.UnWrapFs(f).Features().BucketBased && strings.Contains(strings.Trim(f.Root(), "/"), "/")
} }
// Remove bad characters from Windows file name if set
if opt.SkipBadWindowsCharacters {
t.Logf("Removing bad windows characters from test file")
file2.Path = fstest.WinPath(file2.Path)
}
// Initialise the remote // Initialise the remote
fstest.Initialise() fstest.Initialise()
@ -780,7 +774,7 @@ func Run(t *testing.T, opt *Opt) {
for i := 1; i <= *fstest.ListRetries; i++ { for i := 1; i <= *fstest.ListRetries; i++ {
objs, dirs, err := walk.GetAll(ctx, remote, dir, true, 1) objs, dirs, err := walk.GetAll(ctx, remote, dir, true, 1)
if errors.Cause(err) == fs.ErrorDirNotFound { if errors.Cause(err) == fs.ErrorDirNotFound {
objs, dirs, err = walk.GetAll(ctx, remote, fstest.WinPath(dir), true, 1) objs, dirs, err = walk.GetAll(ctx, remote, dir, true, 1)
} }
require.NoError(t, err) require.NoError(t, err)
objNames = objsToNames(objs) objNames = objsToNames(objs)
@ -803,13 +797,13 @@ func Run(t *testing.T, opt *Opt) {
dir = path.Dir(dir) dir = path.Dir(dir)
if dir == "." { if dir == "." {
dir = "" dir = ""
expectedObjNames = append(expectedObjNames, fstest.WinPath(file1.Path)) expectedObjNames = append(expectedObjNames, file1.Path)
} }
if deepest { if deepest {
expectedObjNames = append(expectedObjNames, fstest.WinPath(file2.Path)) expectedObjNames = append(expectedObjNames, file2.Path)
deepest = false deepest = false
} else { } else {
expectedDirNames = append(expectedDirNames, fstest.WinPath(child)) expectedDirNames = append(expectedDirNames, child)
} }
list(dir, expectedDirNames, expectedObjNames) list(dir, expectedDirNames, expectedObjNames)
} }
@ -829,14 +823,14 @@ func Run(t *testing.T, opt *Opt) {
objs, dirs, err := walk.GetAll(ctx, remote, "", true, -1) objs, dirs, err := walk.GetAll(ctx, remote, "", true, -1)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, []string{ assert.Equal(t, []string{
"hello_ sausage", "hello? sausage",
"hello_ sausage/êé", "hello? sausage/êé",
"hello_ sausage/êé/Hello, 世界", "hello? sausage/êé/Hello, 世界",
"hello_ sausage/êé/Hello, 世界/ _ ' @ _ _ & _ + ≠", "hello? sausage/êé/Hello, 世界/ \" ' @ < > & ? + ≠",
}, dirsToNames(dirs)) }, dirsToNames(dirs))
assert.Equal(t, []string{ assert.Equal(t, []string{
"file name.txt", "file name.txt",
"hello_ sausage/êé/Hello, 世界/ _ ' @ _ _ & _ + ≠/z.txt", "hello? sausage/êé/Hello, 世界/ \" ' @ < > & ? + ≠/z.txt",
}, objsToNames(objs)) }, objsToNames(objs))
}) })
@ -847,12 +841,12 @@ func Run(t *testing.T, opt *Opt) {
objs, dirs, err := walk.GetAll(ctx, remote, path.Dir(path.Dir(path.Dir(path.Dir(file2.Path)))), true, -1) objs, dirs, err := walk.GetAll(ctx, remote, path.Dir(path.Dir(path.Dir(path.Dir(file2.Path)))), true, -1)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, []string{ assert.Equal(t, []string{
"hello_ sausage/êé", "hello? sausage/êé",
"hello_ sausage/êé/Hello, 世界", "hello? sausage/êé/Hello, 世界",
"hello_ sausage/êé/Hello, 世界/ _ ' @ _ _ & _ + ≠", "hello? sausage/êé/Hello, 世界/ \" ' @ < > & ? + ≠",
}, dirsToNames(dirs)) }, dirsToNames(dirs))
assert.Equal(t, []string{ assert.Equal(t, []string{
"hello_ sausage/êé/Hello, 世界/ _ ' @ _ _ & _ + ≠/z.txt", "hello? sausage/êé/Hello, 世界/ \" ' @ < > & ? + ≠/z.txt",
}, objsToNames(objs)) }, objsToNames(objs))
}) })
@ -907,7 +901,7 @@ func Run(t *testing.T, opt *Opt) {
} }
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, []string{file1.Path}, objsToNames(objs)) assert.Equal(t, []string{file1.Path}, objsToNames(objs))
assert.Equal(t, []string{`hello_ sausage`, `hello_ sausage/êé`}, dirsToNames(dirs)) assert.Equal(t, []string{"hello? sausage", "hello? sausage/êé"}, dirsToNames(dirs))
} }
t.Run("FsListLevel2", TestFsListLevel2) t.Run("FsListLevel2", TestFsListLevel2)