From cfe0911e0d9fbfc8a931c981216021689e53595f Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 9 Jun 2022 13:19:11 +0100 Subject: [PATCH] sync: fix tests for overlapping with filter In commit 3ccf222acb9697c3 sync: overlap check is now filter-sensitive The tests were attempting to write invalid objects on some backends due to a leading / on the object name. This fix also adds a few more test cases and makes sure the tests can be run individually. --- fs/operations/operations_test.go | 3 +++ fs/sync/sync_test.go | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.go index 83df26398..10475562a 100644 --- a/fs/operations/operations_test.go +++ b/fs/operations/operations_test.go @@ -1284,6 +1284,7 @@ func TestOverlappingFilterCheckWithoutFilter(t *testing.T) { expected bool }{ {"name", "root", true}, + {"name", "/root", true}, {"namey", "root", false}, {"name", "rooty", false}, {"namey", "rooty", false}, @@ -1320,10 +1321,12 @@ func TestOverlappingFilterCheckWithFilter(t *testing.T) { expected bool }{ {"name", "root", true}, + {"name", "/root", true}, {"name", "root/", true}, {"name", "root" + slash, true}, {"name", "root/exclude", false}, {"name", "root/exclude/", false}, + {"name", "/root/exclude/", false}, {"name", "root" + slash + "exclude", false}, {"name", "root" + slash + "exclude" + slash, false}, {"name", "root/.ignore", false}, diff --git a/fs/sync/sync_test.go b/fs/sync/sync_test.go index 19e225fd9..4bf60c471 100644 --- a/fs/sync/sync_test.go +++ b/fs/sync/sync_test.go @@ -1469,18 +1469,20 @@ func TestSyncOverlapWithFilter(t *testing.T) { FremoteSync3, err := fs.NewFs(ctx, subRemoteName3) require.NoError(t, FremoteSync3.Mkdir(ctx, "")) require.NoError(t, err) - r.WriteObject(context.Background(), "/rclone-sync-test-ignore-file/.ignore", "-", t1) + r.WriteObject(context.Background(), "rclone-sync-test-ignore-file/.ignore", "-", t1) checkErr := func(err error) { require.Error(t, err) assert.True(t, fserrors.IsFatalError(err)) assert.Equal(t, fs.ErrorOverlapping.Error(), err.Error()) + accounting.GlobalStats().ResetCounters() } checkNoErr := func(err error) { require.NoError(t, err) } + accounting.GlobalStats().ResetCounters() checkNoErr(Sync(ctx, FremoteSync, r.Fremote, false)) checkErr(Sync(ctx, r.Fremote, FremoteSync, false)) checkErr(Sync(ctx, r.Fremote, r.Fremote, false))