From fb1bbecb41ce527873ea04c9eca38c7c1dc6ca41 Mon Sep 17 00:00:00 2001 From: Cnly Date: Thu, 23 May 2019 21:10:17 +0800 Subject: [PATCH] fstests: add FsRootCollapse test - #3164 --- fstest/fstests/fstests.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go index 86384c371..99f2ba7bd 100644 --- a/fstest/fstests/fstests.go +++ b/fstest/fstests/fstests.go @@ -1583,6 +1583,27 @@ func Run(t *testing.T, opt *Opt) { }) + // TestFsRootCollapse tests if the root of an fs "collapses" to the + // absolute root. It creates a new fs of the same backend type with its + // root set to a *non-existent* folder, and attempts to read the info of + // an object in that folder, whose name is taken from a directory that + // exists in the absolute root. + // This test is added after + // https://github.com/ncw/rclone/issues/3164. + t.Run("FsRootCollapse", func(t *testing.T) { + deepRemoteName := subRemoteName + "/deeper/nonexisting/directory" + deepRemote, err := fs.NewFs(deepRemoteName) + require.NoError(t, err) + + colonIndex := strings.IndexRune(deepRemoteName, ':') + firstSlashIndex := strings.IndexRune(deepRemoteName, '/') + firstDir := deepRemoteName[colonIndex+1 : firstSlashIndex] + _, err = deepRemote.NewObject(firstDir) + require.Equal(t, fs.ErrorObjectNotFound, err) + // If err is not fs.ErrorObjectNotFound, it means the backend is + // somehow confused about root and absolute root. + }) + // Purge the folder err = operations.Purge(remote, "") require.NoError(t, err)