Repository: rclone/rclone
File: fstest/fstests/fstests.go (Go)

Code before:

				// Now purge it from the root
				err = operations.Purge(ctx, fPurge, "")
				require.NoError(t, err)

				fstest.CheckListingWithPrecision(t, f, []fstest.Item{file1, file2}, []string{
					"hello? sausage",
					"hello? sausage/êé",
					"hello? sausage/êé/Hello, 世界",
					"hello? sausage/êé/Hello, 世界/ \" ' @ < > & ? + ≠",
				}, fs.GetModifyWindow(ctx, f))
			})

			// TestFsListRootedSubdir tests putting and listing with an Fs that is rooted at a subdirectory 2 levels down
			TestFsListRootedSubdir := func(t *testing.T) {
				skipIfNotOk(t)
				newF, err := cache.Get(ctx, subRemoteName+"/hello? sausage/êé")
				assert.NoError(t, err)
				nestedFile := fstest.Item{
					ModTime: fstest.Time("2001-02-03T04:05:06.499999999Z"),
					Path:    "a/b/c/d/e.txt",
				}
				_, _ = testPut(ctx, t, newF, &nestedFile)
				depth := 10

				objs, dirs, err := walk.GetAll(ctx, newF, "", true, depth)
				require.NoError(t, err)
				assert.Equal(t, []string{`Hello, 世界/ " ' @ < > & ? + ≠/z.txt`, nestedFile.Path}, objsToNames(objs))
				assert.Equal(t, []string{`Hello, 世界`, `Hello, 世界/ " ' @ < > & ? + ≠`, "a", "a/b", "a/b/c", "a/b/c/d"}, dirsToNames(dirs))

				objs, dirs, err = walk.GetAll(ctx, newF, "a/b", true, depth)
				require.NoError(t, err)
				assert.Equal(t, []string{"a/b/c/d/e.txt"}, objsToNames(objs))
				assert.Equal(t, []string{"a/b/c", "a/b/c/d"}, dirsToNames(dirs))

				newerF, err := cache.Get(ctx, subRemoteName+"/hello? sausage/êé"+"/a/b")
				assert.NoError(t, err)
				objs, dirs, err = walk.GetAll(ctx, newerF, "", true, depth)
				require.NoError(t, err)
				assert.Equal(t, []string{"c/d/e.txt"}, objsToNames(objs))
				assert.Equal(t, []string{"c", "c/d"}, dirsToNames(dirs))

				objs, dirs, err = walk.GetAll(ctx, f, "hello? sausage/êé", true, depth)
				require.NoError(t, err)
				assert.Equal(t, []string{`hello? sausage/êé/Hello, 世界/ " ' @ < > & ? + ≠/z.txt`, "hello? sausage/êé/" + nestedFile.Path}, objsToNames(objs))
				assert.Equal(t, []string{`hello? sausage/êé/Hello, 世界`, `hello? sausage/êé/Hello, 世界/ " ' @ < > & ? + ≠`, "hello? sausage/êé/a", "hello? sausage/êé/a/b", "hello? sausage/êé/a/b/c", "hello? sausage/êé/a/b/c/d"}, dirsToNames(dirs))

				// cleanup
				err = operations.Purge(ctx, newF, "a")
				require.NoError(t, err)
			}

Review comment (suggestion):
Can you use `fstest.CheckListing` to see whether everything is OK? That does retries and exponential backoff which `walk.GetAll` doesn't which is often needed on eventually consistent backends.

Code after:

				// Now purge it from the root
				err = operations.Purge(ctx, fPurge, "")
				require.NoError(t, err)

				fstest.CheckListingWithPrecision(t, f, []fstest.Item{file1, file2}, []string{
					"hello? sausage",
					"hello? sausage/êé",
					"hello? sausage/êé/Hello, 世界",
					"hello? sausage/êé/Hello, 世界/ \" ' @ < > & ? + ≠",
				}, fs.GetModifyWindow(ctx, f))
			})

			// TestFsListRootedSubdir tests putting and listing with an Fs that is rooted at a subdirectory 2 levels down
			TestFsListRootedSubdir := func(t *testing.T) {
				skipIfNotOk(t)
				newF, err := cache.Get(ctx, subRemoteName+"/hello? sausage/êé")
				assert.NoError(t, err)
				nestedFile := fstest.Item{
					ModTime: fstest.Time("2001-02-03T04:05:06.499999999Z"),
					Path:    "a/b/c/d/e.txt",
				}
				_, _ = testPut(ctx, t, newF, &nestedFile)

				objs, dirs, err := walk.GetAll(ctx, newF, "", true, 10)
				require.NoError(t, err)
				assert.Equal(t, []string{`Hello, 世界/ " ' @ < > & ? + ≠/z.txt`, nestedFile.Path}, objsToNames(objs))
				assert.Equal(t, []string{`Hello, 世界`, `Hello, 世界/ " ' @ < > & ? + ≠`, "a", "a/b", "a/b/c", "a/b/c/d"}, dirsToNames(dirs))

				// cleanup
				err = operations.Purge(ctx, newF, "a")
				require.NoError(t, err)
			}
			t.Run("FsListRootedSubdir", TestFsListRootedSubdir)

			// TestFsCopy tests Copy
			t.Run("FsCopy", func(t *testing.T) {
				skipIfNotOk(t)

				// Check have Copy
				doCopy := f.Features().Copy
				if doCopy == nil {
					t.Skip("FS has no Copier interface")
				}

				// Test with file2 so have + and ' ' in file name
				var file2Copy = file2
				file2Copy.Path += "-copy"

				// do the copy
				src := fstest.NewObject(ctx, t, f, file2.Path)