forked from TrueCloudLab/rclone
tests for --exclude-if-present
This commit is contained in:
parent
538246f6c3
commit
7d3abdc463
2 changed files with 104 additions and 2 deletions
|
@ -743,6 +743,8 @@ func TestListDirSorted(t *testing.T) {
|
||||||
r.WriteObject("zend.txt", "hello", t1),
|
r.WriteObject("zend.txt", "hello", t1),
|
||||||
r.WriteObject("sub dir/hello world", "hello world", t1),
|
r.WriteObject("sub dir/hello world", "hello world", t1),
|
||||||
r.WriteObject("sub dir/hello world2", "hello world", t1),
|
r.WriteObject("sub dir/hello world2", "hello world", t1),
|
||||||
|
r.WriteObject("sub dir/ignore dir/.ignore", "", t1),
|
||||||
|
r.WriteObject("sub dir/ignore dir/should be ignored", "to ignore", t1),
|
||||||
r.WriteObject("sub dir/sub sub dir/hello world3", "hello world", t1),
|
r.WriteObject("sub dir/sub sub dir/hello world3", "hello world", t1),
|
||||||
}
|
}
|
||||||
fstest.CheckItems(t, r.Fremote, files...)
|
fstest.CheckItems(t, r.Fremote, files...)
|
||||||
|
@ -779,15 +781,42 @@ func TestListDirSorted(t *testing.T) {
|
||||||
|
|
||||||
items, err = fs.ListDirSorted(r.Fremote, true, "sub dir")
|
items, err = fs.ListDirSorted(r.Fremote, true, "sub dir")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, items, 3)
|
require.Len(t, items, 4)
|
||||||
assert.Equal(t, "sub dir/hello world", str(0))
|
assert.Equal(t, "sub dir/hello world", str(0))
|
||||||
assert.Equal(t, "sub dir/hello world2", str(1))
|
assert.Equal(t, "sub dir/hello world2", str(1))
|
||||||
assert.Equal(t, "sub dir/sub sub dir/", str(2))
|
assert.Equal(t, "sub dir/ignore dir/", str(2))
|
||||||
|
assert.Equal(t, "sub dir/sub sub dir/", str(3))
|
||||||
|
|
||||||
|
items, err = fs.ListDirSorted(r.Fremote, false, "sub dir")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, items, 2)
|
||||||
|
assert.Equal(t, "sub dir/ignore dir/", str(0))
|
||||||
|
assert.Equal(t, "sub dir/sub sub dir/", str(1))
|
||||||
|
|
||||||
|
// testing ignore file
|
||||||
|
fs.Config.Filter.ExcludeFile = ".ignore"
|
||||||
|
|
||||||
items, err = fs.ListDirSorted(r.Fremote, false, "sub dir")
|
items, err = fs.ListDirSorted(r.Fremote, false, "sub dir")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, items, 1)
|
require.Len(t, items, 1)
|
||||||
assert.Equal(t, "sub dir/sub sub dir/", str(0))
|
assert.Equal(t, "sub dir/sub sub dir/", str(0))
|
||||||
|
|
||||||
|
items, err = fs.ListDirSorted(r.Fremote, false, "sub dir/ignore dir")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, items, 0)
|
||||||
|
|
||||||
|
items, err = fs.ListDirSorted(r.Fremote, true, "sub dir/ignore dir")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, items, 2)
|
||||||
|
assert.Equal(t, "sub dir/ignore dir/.ignore", str(0))
|
||||||
|
assert.Equal(t, "sub dir/ignore dir/should be ignored", str(1))
|
||||||
|
|
||||||
|
fs.Config.Filter.ExcludeFile = ""
|
||||||
|
items, err = fs.ListDirSorted(r.Fremote, false, "sub dir/ignore dir")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, items, 2)
|
||||||
|
assert.Equal(t, "sub dir/ignore dir/.ignore", str(0))
|
||||||
|
assert.Equal(t, "sub dir/ignore dir/should be ignored", str(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
type byteReader struct {
|
type byteReader struct {
|
||||||
|
|
|
@ -588,3 +588,76 @@ a/
|
||||||
assert.Equal(t, test.want, r.String(), fmt.Sprintf("%+v", test))
|
assert.Equal(t, test.want, r.String(), fmt.Sprintf("%+v", test))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWalkRDirTreeExclude(t *testing.T) {
|
||||||
|
for _, test := range []struct {
|
||||||
|
entries DirEntries
|
||||||
|
want string
|
||||||
|
err error
|
||||||
|
root string
|
||||||
|
level int
|
||||||
|
excludeFile string
|
||||||
|
includeAll bool
|
||||||
|
}{
|
||||||
|
{DirEntries{mockObject("a"), mockObject("ignore")}, "", nil, "", -1, "ignore", false},
|
||||||
|
{DirEntries{mockObject("a")}, `/
|
||||||
|
a
|
||||||
|
`, nil, "", -1, "ignore", false},
|
||||||
|
{DirEntries{
|
||||||
|
mockObject("a"),
|
||||||
|
mockObject("b/b"),
|
||||||
|
mockObject("b/.ignore"),
|
||||||
|
}, `/
|
||||||
|
a
|
||||||
|
`, nil, "", -1, ".ignore", false},
|
||||||
|
{DirEntries{
|
||||||
|
mockObject("a"),
|
||||||
|
mockObject("b/.ignore"),
|
||||||
|
mockObject("b/b"),
|
||||||
|
}, `/
|
||||||
|
a
|
||||||
|
b/
|
||||||
|
b/
|
||||||
|
.ignore
|
||||||
|
b
|
||||||
|
`, nil, "", -1, ".ignore", true},
|
||||||
|
{DirEntries{
|
||||||
|
mockObject("a"),
|
||||||
|
mockObject("b/b"),
|
||||||
|
mockObject("b/c/d/e"),
|
||||||
|
mockObject("b/c/ign"),
|
||||||
|
mockObject("b/c/x"),
|
||||||
|
}, `/
|
||||||
|
a
|
||||||
|
b/
|
||||||
|
b/
|
||||||
|
b
|
||||||
|
`, nil, "", -1, "ign", false},
|
||||||
|
{DirEntries{
|
||||||
|
mockObject("a"),
|
||||||
|
mockObject("b/b"),
|
||||||
|
mockObject("b/c/d/e"),
|
||||||
|
mockObject("b/c/ign"),
|
||||||
|
mockObject("b/c/x"),
|
||||||
|
}, `/
|
||||||
|
a
|
||||||
|
b/
|
||||||
|
b/
|
||||||
|
b
|
||||||
|
c/
|
||||||
|
b/c/
|
||||||
|
d/
|
||||||
|
ign
|
||||||
|
x
|
||||||
|
b/c/d/
|
||||||
|
e
|
||||||
|
`, nil, "", -1, "ign", true},
|
||||||
|
} {
|
||||||
|
Config.Filter.ExcludeFile = test.excludeFile
|
||||||
|
r, err := walkRDirTree(nil, test.root, test.includeAll, test.level, makeListRCallback(test.entries, test.err))
|
||||||
|
assert.Equal(t, test.err, err, fmt.Sprintf("%+v", test))
|
||||||
|
assert.Equal(t, test.want, r.String(), fmt.Sprintf("%+v", test))
|
||||||
|
}
|
||||||
|
// Set to default value, to avoid side effects
|
||||||
|
Config.Filter.ExcludeFile = ""
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue