1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

fstest: remove WinPath from fstest.Item

This commit is contained in:
Fabian Möller
2018-11-02 13:16:13 +01:00
committed by Nick Craig-Wood
parent 4627ac5709
commit 97a218903c
3 changed files with 12 additions and 33 deletions

View File

@@ -88,7 +88,6 @@ type Item struct {
Hashes map[hash.Type]string
ModTime time.Time
Size int64
WinPath string
}
// NewItem creates an item from a string content
@@ -181,7 +180,6 @@ func NewItems(items []Item) *Items {
// Fill up byName
for i := range items {
is.byName[Normalize(items[i].Path)] = &items[i]
is.byNameAlt[Normalize(items[i].WinPath)] = &items[i]
}
return is
}
@@ -196,7 +194,6 @@ func (is *Items) Find(t *testing.T, obj fs.Object, precision time.Duration) {
}
if i != nil {
delete(is.byName, i.Path)
delete(is.byName, i.WinPath)
i.Check(t, obj, precision)
}
}
@@ -214,21 +211,14 @@ func (is *Items) Done(t *testing.T) {
// makeListingFromItems returns a string representation of the items
//
// it returns two possible strings, one normal and one for windows
func makeListingFromItems(items []Item) (string, string) {
nameLengths1 := make([]string, len(items))
nameLengths2 := make([]string, len(items))
func makeListingFromItems(items []Item) string {
nameLengths := make([]string, len(items))
for i, item := range items {
remote1 := Normalize(item.Path)
remote2 := remote1
if item.WinPath != "" {
remote2 = item.WinPath
}
nameLengths1[i] = fmt.Sprintf("%s (%d)", remote1, item.Size)
nameLengths2[i] = fmt.Sprintf("%s (%d)", remote2, item.Size)
remote := Normalize(item.Path)
nameLengths[i] = fmt.Sprintf("%s (%d)", remote, item.Size)
}
sort.Strings(nameLengths1)
sort.Strings(nameLengths2)
return strings.Join(nameLengths1, ", "), strings.Join(nameLengths2, ", ")
sort.Strings(nameLengths)
return strings.Join(nameLengths, ", ")
}
// makeListingFromObjects returns a string representation of the objects
@@ -285,7 +275,7 @@ func CheckListingWithRoot(t *testing.T, f fs.Fs, dir string, items []Item, expec
var err error
var retries = *ListRetries
sleep := time.Second / 2
wantListing1, wantListing2 := makeListingFromItems(items)
wantListing := makeListingFromItems(items)
gotListing := "<unset>"
listingOK := false
for i := 1; i <= retries; i++ {
@@ -295,7 +285,7 @@ func CheckListingWithRoot(t *testing.T, f fs.Fs, dir string, items []Item, expec
}
gotListing = makeListingFromObjects(objs)
listingOK = wantListing1 == gotListing || wantListing2 == gotListing
listingOK = wantListing == gotListing
if listingOK && (expectedDirs == nil || len(dirs) == len(expectedDirs)) {
// Put an extra sleep in if we did any retries just to make sure it really
// is consistent (here is looking at you Amazon Drive!)
@@ -314,7 +304,7 @@ func CheckListingWithRoot(t *testing.T, f fs.Fs, dir string, items []Item, expec
doDirCacheFlush()
}
}
assert.True(t, listingOK, fmt.Sprintf("listing wrong, want\n %s or\n %s got\n %s", wantListing1, wantListing2, gotListing))
assert.True(t, listingOK, fmt.Sprintf("listing wrong, want\n %s got\n %s", wantListing, gotListing))
for _, obj := range objs {
require.NotNil(t, obj)
is.Find(t, obj, precision)
@@ -368,7 +358,7 @@ func CompareItems(t *testing.T, entries fs.DirEntries, items []Item, expectedDir
is := NewItems(items)
var objs []fs.Object
var dirs []fs.Directory
wantListing1, wantListing2 := makeListingFromItems(items)
wantListing := makeListingFromItems(items)
for _, entry := range entries {
switch x := entry.(type) {
case fs.Directory:
@@ -382,8 +372,8 @@ func CompareItems(t *testing.T, entries fs.DirEntries, items []Item, expectedDir
}
gotListing := makeListingFromObjects(objs)
listingOK := wantListing1 == gotListing || wantListing2 == gotListing
assert.True(t, listingOK, fmt.Sprintf("%s not equal, want\n %s or\n %s got\n %s", what, wantListing1, wantListing2, gotListing))
listingOK := wantListing == gotListing
assert.True(t, listingOK, fmt.Sprintf("%s not equal, want\n %s got\n %s", what, wantListing, gotListing))
for _, obj := range objs {
require.NotNil(t, obj)
is.Find(t, obj, precision)