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

Code before:
					"dirToPurgeFromRoot",
					"hello? sausage",
					"hello? sausage/êé",
					"hello? sausage/êé/Hello, 世界",
					"hello? sausage/êé/Hello, 世界/ \" ' @ < > & ? + ≠",
				}, fs.GetModifyWindow(ctx, f))

				// Create a new Fs pointing at the directory
				remoteName := subRemoteName + "/" + "dirToPurgeFromRoot"
				fPurge, err := fs.NewFs(context.Background(), remoteName)
				require.NoError(t, err)

				// 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))

Review comment (bug):
Can you cut this test down the the minimum possible to reproduce the bug? Remember that this test gets run on 100 different backends in the integration tests!

Code after:
					"dirToPurgeFromRoot",
					"hello? sausage",
					"hello? sausage/êé",
					"hello? sausage/êé/Hello, 世界",
					"hello? sausage/êé/Hello, 世界/ \" ' @ < > & ? + ≠",
				}, fs.GetModifyWindow(ctx, f))

				// Create a new Fs pointing at the directory
				remoteName := subRemoteName + "/" + "dirToPurgeFromRoot"
				fPurge, err := fs.NewFs(context.Background(), remoteName)
				require.NoError(t, err)

				// 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