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

@ -1323,7 +1323,6 @@ func TestDirMove(t *testing.T) {
for i := range files { for i := range files {
files[i].Path = strings.Replace(files[i].Path, "A1/", "A2/", -1) files[i].Path = strings.Replace(files[i].Path, "A1/", "A2/", -1)
files[i].WinPath = ""
} }
fstest.CheckListingWithPrecision( fstest.CheckListingWithPrecision(
@ -1353,7 +1352,6 @@ func TestDirMove(t *testing.T) {
for i := range files { for i := range files {
files[i].Path = strings.Replace(files[i].Path, "A2/", "A3/", -1) files[i].Path = strings.Replace(files[i].Path, "A2/", "A3/", -1)
files[i].WinPath = ""
} }
fstest.CheckListingWithPrecision( fstest.CheckListingWithPrecision(

View File

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

View File

@ -292,7 +292,6 @@ func Run(t *testing.T, opt *Opt) {
file2 = fstest.Item{ file2 = fstest.Item{
ModTime: fstest.Time("2001-02-03T04:05:10.123123123Z"), ModTime: fstest.Time("2001-02-03T04:05:10.123123123Z"),
Path: `hello? sausage/êé/Hello, 世界/ " ' @ < > & ? + ≠/z.txt`, Path: `hello? sausage/êé/Hello, 世界/ " ' @ < > & ? + ≠/z.txt`,
WinPath: `hello_ sausage/êé/Hello, 世界/ _ ' @ _ _ & _ + ≠/z.txt`,
} }
isLocalRemote bool isLocalRemote bool
purged bool // whether the dir has been purged or not purged bool // whether the dir has been purged or not
@ -832,10 +831,6 @@ func Run(t *testing.T, opt *Opt) {
dir, _ := path.Split(fileName) dir, _ := path.Split(fileName)
dir = dir[:len(dir)-1] dir = dir[:len(dir)-1]
objs, dirs, err = walk.GetAll(context.Background(), remote, dir, true, -1) objs, dirs, err = walk.GetAll(context.Background(), remote, dir, true, -1)
if err != fs.ErrorDirNotFound {
break
}
fileName = file2.WinPath
} }
require.NoError(t, err) require.NoError(t, err)
require.Len(t, objs, 1) require.Len(t, objs, 1)
@ -951,7 +946,6 @@ func Run(t *testing.T, opt *Opt) {
// check happy path, i.e. no naming conflicts when rename and move are two // check happy path, i.e. no naming conflicts when rename and move are two
// separate operations // separate operations
file2Move.Path = "other.txt" file2Move.Path = "other.txt"
file2Move.WinPath = ""
src := findObject(t, remote, file2.Path) src := findObject(t, remote, file2.Path)
dst, err := doMove(context.Background(), src, file2Move.Path) dst, err := doMove(context.Background(), src, file2Move.Path)
if err == fs.ErrorCantMove { if err == fs.ErrorCantMove {
@ -1036,7 +1030,6 @@ func Run(t *testing.T, opt *Opt) {
file1Copy.Path = path.Join(newName, file1.Path) file1Copy.Path = path.Join(newName, file1.Path)
file2Copy := file2 file2Copy := file2
file2Copy.Path = path.Join(newName, file2.Path) file2Copy.Path = path.Join(newName, file2.Path)
file2Copy.WinPath = path.Join(newName, file2.WinPath)
fstest.CheckListingWithPrecision(t, newRemote, []fstest.Item{file2Copy, file1Copy}, []string{ fstest.CheckListingWithPrecision(t, newRemote, []fstest.Item{file2Copy, file1Copy}, []string{
"new_name", "new_name",
"new_name/sub_new_name", "new_name/sub_new_name",
@ -1261,7 +1254,6 @@ func Run(t *testing.T, opt *Opt) {
remoteName := subRemoteName + "/" + file2.Path remoteName := subRemoteName + "/" + file2.Path
file2Copy := file2 file2Copy := file2
file2Copy.Path = "z.txt" file2Copy.Path = "z.txt"
file2Copy.WinPath = ""
fileRemote, err := fs.NewFs(remoteName) fileRemote, err := fs.NewFs(remoteName)
require.NotNil(t, fileRemote) require.NotNil(t, fileRemote)
assert.Equal(t, fs.ErrorIsFile, err) assert.Equal(t, fs.ErrorIsFile, err)
@ -1304,7 +1296,6 @@ func Run(t *testing.T, opt *Opt) {
file1Root.Path = path.Join(configLeaf, file1Root.Path) file1Root.Path = path.Join(configLeaf, file1Root.Path)
file2Root := file2 file2Root := file2
file2Root.Path = path.Join(configLeaf, file2Root.Path) file2Root.Path = path.Join(configLeaf, file2Root.Path)
file2Root.WinPath = path.Join(configLeaf, file2Root.WinPath)
var dirs []string var dirs []string
dir := file2.Path dir := file2.Path
for { for {