"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
fs: make sync and operations tests use context instead of global variables
Nick Craig-Wood25d5ed763cfe
diff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.goindex 4fb90bee9..56a864ad1 100644--- a/fs/operations/operations_test.go+++ b/fs/operations/operations_test.go@@ -106,7 +106,7 @@ func TestLs(t *testing.T) {func TestLsWithFilesFrom(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1)@@ -129,11 +129,7 @@ func TestLsWithFilesFrom(t *testing.T) {assert.Equal(t, " 60 potato2\n", buf.String())// Now try with --no-traverse- oldNoTraverse := ci.NoTraverseci.NoTraverse = true- defer func() {- ci.NoTraverse = oldNoTraverse- }()buf.Reset()err = operations.List(ctx, r.Fremote, &buf)@@ -336,11 +332,7 @@ func TestHashSums(t *testing.T) {func TestSuffixName(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)- origSuffix, origKeepExt := ci.Suffix, ci.SuffixKeepExtension- defer func() {- ci.Suffix, ci.SuffixKeepExtension = origSuffix, origKeepExt- }()+ ctx, ci := fs.AddConfig(ctx)for _, test := range []struct {remote stringsuffix string@@ -365,7 +357,7 @@ func TestSuffixName(t *testing.T) {func TestCount(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1)@@ -376,7 +368,6 @@ func TestCount(t *testing.T) {// Check the MaxDepth tooci.MaxDepth = 1- defer func() { ci.MaxDepth = -1 }()objects, size, err := operations.Count(ctx, r.Fremote)require.NoError(t, err)@@ -386,7 +377,10 @@ func TestCount(t *testing.T) {func TestDelete(t *testing.T) {ctx := context.Background()- fi := filter.GetConfig(ctx)+ fi, err := filter.NewFilter(nil)+ require.NoError(t, err)+ fi.Opt.MaxSize = 60+ ctx = filter.ReplaceConfig(ctx, fi)r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteObject(ctx, "small", "1234567890", t2) // 10 bytes@@ -394,12 +388,7 @@ func TestDelete(t *testing.T) {file3 := r.WriteObject(ctx, "large", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", t1) // 100 bytesfstest.CheckItems(t, r.Fremote, file1, file2, file3)- fi.Opt.MaxSize = 60- defer func() {- fi.Opt.MaxSize = -1- }()-- err := operations.Delete(ctx, r.Fremote)+ err = operations.Delete(ctx, r.Fremote)require.NoError(t, err)fstest.CheckItems(t, r.Fremote, file3)}@@ -695,7 +684,7 @@ func TestRmdirsWithFilter(t *testing.T) {func TestCopyURL(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()@@ -750,10 +739,7 @@ func TestCopyURL(t *testing.T) {// check when reading from unverified HTTPS serverci.InsecureSkipVerify = truefshttp.ResetTransport()- defer func() {- ci.InsecureSkipVerify = false- fshttp.ResetTransport()- }()+ defer fshttp.ResetTransport()tss := httptest.NewTLSServer(handler)defer tss.Close()@@ -863,18 +849,14 @@ func TestCaseInsensitiveMoveFile(t *testing.T) {func TestMoveFileBackupDir(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()if !operations.CanServerSideMove(r.Fremote) {t.Skip("Skipping test as remote does not support server-side move or copy")}- oldBackupDir := ci.BackupDirci.BackupDir = r.FremoteName + "/backup"- defer func() {- ci.BackupDir = oldBackupDir- }()file1 := r.WriteFile("dst/file1", "file1 contents", t1)fstest.CheckItems(t, r.Flocal, file1)@@ -918,18 +900,14 @@ func TestCopyFile(t *testing.T) {func TestCopyFileBackupDir(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()if !operations.CanServerSideMove(r.Fremote) {t.Skip("Skipping test as remote does not support server-side move or copy")}- oldBackupDir := ci.BackupDirci.BackupDir = r.FremoteName + "/backup"- defer func() {- ci.BackupDir = oldBackupDir- }()file1 := r.WriteFile("dst/file1", "file1 contents", t1)fstest.CheckItems(t, r.Flocal, file1)@@ -947,14 +925,11 @@ func TestCopyFileBackupDir(t *testing.T) {// Test with CompareDest setfunc TestCopyFileCompareDest(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.CompareDest = []string{r.FremoteName + "/CompareDest"}- defer func() {- ci.CompareDest = nil- }()fdst, err := fs.NewFs(ctx, r.FremoteName+"/dst")require.NoError(t, err)@@ -1029,7 +1004,7 @@ func TestCopyFileCompareDest(t *testing.T) {// Test with CopyDest setfunc TestCopyFileCopyDest(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()@@ -1038,9 +1013,6 @@ func TestCopyFileCopyDest(t *testing.T) {}ci.CopyDest = []string{r.FremoteName + "/CopyDest"}- defer func() {- ci.CopyDest = nil- }()fdst, err := fs.NewFs(ctx, r.FremoteName+"/dst")require.NoError(t, err)@@ -1396,11 +1368,7 @@ func TestDirMove(t *testing.T) {// Disable DirMovefeatures := r.Fremote.Features()- oldDirMove := features.DirMovefeatures.DirMove = nil- defer func() {- features.DirMove = oldDirMove- }()require.NoError(t, operations.DirMove(ctx, r.Fremote, "A2", "A3"))@@ -1447,13 +1415,9 @@ func TestGetFsInfo(t *testing.T) {func TestRcat(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)check := func(withChecksum, ignoreChecksum bool) {- checksumBefore, ignoreChecksumBefore := ci.CheckSum, ci.IgnoreChecksumci.CheckSum, ci.IgnoreChecksum = withChecksum, ignoreChecksum- defer func() {- ci.CheckSum, ci.IgnoreChecksum = checksumBefore, ignoreChecksumBefore- }()var prefix stringif withChecksum {@@ -1465,15 +1429,11 @@ func TestRcat(t *testing.T) {prefix = "ignore_checksum_"}- ctx := context.Background()r := fstest.NewRun(t)defer r.Finalise()if *fstest.SizeLimit > 0 && int64(ci.StreamingUploadCutoff) > *fstest.SizeLimit {savedCutoff := ci.StreamingUploadCutoff- defer func() {- ci.StreamingUploadCutoff = savedCutoff- }()ci.StreamingUploadCutoff = fs.SizeSuffix(*fstest.SizeLimit)t.Logf("Adjust StreamingUploadCutoff to size limit %s (was %s)", ci.StreamingUploadCutoff, savedCutoff)}@@ -1537,17 +1497,10 @@ func TestRcatSize(t *testing.T) {func TestCopyFileMaxTransfer(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()- old := ci.MaxTransfer- oldMode := ci.CutoffMode-- defer func() {- ci.MaxTransfer = old- ci.CutoffMode = oldMode- accounting.Stats(ctx).ResetCounters()- }()+ defer accounting.Stats(ctx).ResetCounters()const sizeCutoff = 2048file1 := r.WriteFile("TestCopyFileMaxTransfer/file1", "file1 contents", t1)diff --git a/fs/sync/sync_test.go b/fs/sync/sync_test.goindex 3d7b54831..823ca7759 100644--- a/fs/sync/sync_test.go+++ b/fs/sync/sync_test.go@@ -39,7 +39,7 @@ func TestMain(m *testing.M) {// Check dry run is workingfunc TestCopyWithDryRun(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteFile("sub dir/hello world", "hello world", t1)@@ -47,7 +47,6 @@ func TestCopyWithDryRun(t *testing.T) {ci.DryRun = trueerr := CopyDir(ctx, r.Fremote, r.Flocal, false)- ci.DryRun = falserequire.NoError(t, err)fstest.CheckItems(t, r.Flocal, file1)@@ -87,12 +86,11 @@ func TestCopyMissingDirectory(t *testing.T) {// Now with --no-traversefunc TestCopyNoTraverse(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.NoTraverse = true- defer func() { ci.NoTraverse = false }()file1 := r.WriteFile("sub dir/hello world", "hello world", t1)@@ -106,12 +104,11 @@ func TestCopyNoTraverse(t *testing.T) {// Now with --check-firstfunc TestCopyCheckFirst(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.CheckFirst = true- defer func() { ci.CheckFirst = false }()file1 := r.WriteFile("sub dir/hello world", "hello world", t1)@@ -125,12 +122,11 @@ func TestCopyCheckFirst(t *testing.T) {// Now with --no-traversefunc TestSyncNoTraverse(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.NoTraverse = true- defer func() { ci.NoTraverse = false }()file1 := r.WriteFile("sub dir/hello world", "hello world", t1)@@ -145,7 +141,7 @@ func TestSyncNoTraverse(t *testing.T) {// Test copy with depthfunc TestCopyWithDepth(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteFile("sub dir/hello world", "hello world", t1)@@ -153,7 +149,6 @@ func TestCopyWithDepth(t *testing.T) {// Check the MaxDepth tooci.MaxDepth = 1- defer func() { ci.MaxDepth = -1 }()err := CopyDir(ctx, r.Fremote, r.Flocal, false)require.NoError(t, err)@@ -165,7 +160,7 @@ func TestCopyWithDepth(t *testing.T) {// Test copy with files fromfunc testCopyWithFilesFrom(t *testing.T, noTraverse bool) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteFile("potato2", "hello world", t1)@@ -180,16 +175,10 @@ func testCopyWithFilesFrom(t *testing.T, noTraverse bool) {// Change the active filterctx = filter.ReplaceConfig(ctx, f)- oldNoTraverse := ci.NoTraverseci.NoTraverse = noTraverse- unpatch := func() {- ci.NoTraverse = oldNoTraverse- }- defer unpatch()err = CopyDir(ctx, r.Fremote, r.Flocal, false)require.NoError(t, err)- unpatch()fstest.CheckItems(t, r.Flocal, file1, file2)fstest.CheckItems(t, r.Fremote, file1)@@ -337,11 +326,10 @@ func TestCopyRedownload(t *testing.T) {// to be transferred on the second sync.func TestSyncBasedOnCheckSum(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.CheckSum = true- defer func() { ci.CheckSum = false }()file1 := r.WriteFile("check sum", "-", t1)fstest.CheckItems(t, r.Flocal, file1)@@ -373,11 +361,10 @@ func TestSyncBasedOnCheckSum(t *testing.T) {// only, we expect nothing to to be transferred on the second sync.func TestSyncSizeOnly(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.SizeOnly = true- defer func() { ci.SizeOnly = false }()file1 := r.WriteFile("sizeonly", "potato", t1)fstest.CheckItems(t, r.Flocal, file1)@@ -409,11 +396,10 @@ func TestSyncSizeOnly(t *testing.T) {// transferred on the second sync.func TestSyncIgnoreSize(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.IgnoreSize = true- defer func() { ci.IgnoreSize = false }()file1 := r.WriteFile("ignore-size", "contents", t1)fstest.CheckItems(t, r.Flocal, file1)@@ -442,7 +428,7 @@ func TestSyncIgnoreSize(t *testing.T) {func TestSyncIgnoreTimes(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteBoth(ctx, "existing", "potato", t1)@@ -457,7 +443,6 @@ func TestSyncIgnoreTimes(t *testing.T) {assert.Equal(t, int64(0), accounting.GlobalStats().GetTransfers())ci.IgnoreTimes = true- defer func() { ci.IgnoreTimes = false }()accounting.GlobalStats().ResetCounters()err = Sync(ctx, r.Fremote, r.Flocal, false)@@ -473,13 +458,12 @@ func TestSyncIgnoreTimes(t *testing.T) {func TestSyncIgnoreExisting(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteFile("existing", "potato", t1)ci.IgnoreExisting = true- defer func() { ci.IgnoreExisting = false }()accounting.GlobalStats().ResetCounters()err := Sync(ctx, r.Fremote, r.Flocal, false)@@ -498,13 +482,10 @@ func TestSyncIgnoreExisting(t *testing.T) {func TestSyncIgnoreErrors(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)ci.IgnoreErrors = true- defer func() {- ci.IgnoreErrors = false- r.Finalise()- }()+ defer r.Finalise()file1 := r.WriteFile("a/potato2", "------------------------------------------------------------", t1)file2 := r.WriteObject(ctx, "b/potato", "SMALLER BUT SAME DATE", t2)file3 := r.WriteBoth(ctx, "c/non empty space", "AhHa!", t2)@@ -572,7 +553,7 @@ func TestSyncIgnoreErrors(t *testing.T) {func TestSyncAfterChangingModtimeOnly(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteFile("empty space", "-", t2)@@ -582,7 +563,6 @@ func TestSyncAfterChangingModtimeOnly(t *testing.T) {fstest.CheckItems(t, r.Fremote, file2)ci.DryRun = true- defer func() { ci.DryRun = false }()accounting.GlobalStats().ResetCounters()err := Sync(ctx, r.Fremote, r.Flocal, false)@@ -603,7 +583,7 @@ func TestSyncAfterChangingModtimeOnly(t *testing.T) {func TestSyncAfterChangingModtimeOnlyWithNoUpdateModTime(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()@@ -613,9 +593,6 @@ func TestSyncAfterChangingModtimeOnlyWithNoUpdateModTime(t *testing.T) {}ci.NoUpdateModTime = true- defer func() {- ci.NoUpdateModTime = false- }()file1 := r.WriteFile("empty space", "-", t2)file2 := r.WriteObject(ctx, "empty space", "-", t1)@@ -716,7 +693,7 @@ func TestSyncAfterChangingContentsOnly(t *testing.T) {// Sync after removing a file and adding a file --dry-runfunc TestSyncAfterRemovingAFileAndAddingAFileDryRun(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteFile("potato2", "------------------------------------------------------------", t1)@@ -734,8 +711,7 @@ func TestSyncAfterRemovingAFileAndAddingAFileDryRun(t *testing.T) {}// Sync after removing a file and adding a file-func TestSyncAfterRemovingAFileAndAddingAFile(t *testing.T) {- ctx := context.Background()+func testSyncAfterRemovingAFileAndAddingAFile(ctx context.Context, t *testing.T) {r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteFile("potato2", "------------------------------------------------------------", t1)@@ -751,9 +727,12 @@ func TestSyncAfterRemovingAFileAndAddingAFile(t *testing.T) {fstest.CheckItems(t, r.Fremote, file1, file3)}+func TestSyncAfterRemovingAFileAndAddingAFile(t *testing.T) {+ testSyncAfterRemovingAFileAndAddingAFile(context.Background(), t)+}+// Sync after removing a file and adding a file-func TestSyncAfterRemovingAFileAndAddingAFileSubDir(t *testing.T) {- ctx := context.Background()+func testSyncAfterRemovingAFileAndAddingAFileSubDir(ctx context.Context, t *testing.T) {r := fstest.NewRun(t)defer r.Finalise()file1 := r.WriteFile("a/potato2", "------------------------------------------------------------", t1)@@ -823,6 +802,10 @@ func TestSyncAfterRemovingAFileAndAddingAFileSubDir(t *testing.T) {)}+func TestSyncAfterRemovingAFileAndAddingAFileSubDir(t *testing.T) {+ testSyncAfterRemovingAFileAndAddingAFileSubDir(context.Background(), t)+}+// Sync after removing a file and adding a file with IO Errorsfunc TestSyncAfterRemovingAFileAndAddingAFileSubDirWithErrors(t *testing.T) {ctx := context.Background()@@ -909,38 +892,29 @@ func TestSyncDeleteAfter(t *testing.T) {// Sync test delete duringfunc TestSyncDeleteDuring(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)ci.DeleteMode = fs.DeleteModeDuring- defer func() {- ci.DeleteMode = fs.DeleteModeDefault- }()- TestSyncAfterRemovingAFileAndAddingAFile(t)+ testSyncAfterRemovingAFileAndAddingAFile(ctx, t)}// Sync test delete beforefunc TestSyncDeleteBefore(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)ci.DeleteMode = fs.DeleteModeBefore- defer func() {- ci.DeleteMode = fs.DeleteModeDefault- }()- TestSyncAfterRemovingAFileAndAddingAFile(t)+ testSyncAfterRemovingAFileAndAddingAFile(ctx, t)}// Copy test delete before - shouldn't delete anythingfunc TestCopyDeleteBefore(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.DeleteMode = fs.DeleteModeBefore- defer func() {- ci.DeleteMode = fs.DeleteModeDefault- }()file1 := r.WriteObject(ctx, "potato", "hopefully not deleted", t1)file2 := r.WriteFile("potato2", "hopefully copied in", t1)@@ -966,14 +940,13 @@ func TestSyncWithExclude(t *testing.T) {fstest.CheckItems(t, r.Fremote, file1, file2)fstest.CheckItems(t, r.Flocal, file1, file2, file3)- fi := filter.GetConfig(ctx)+ fi, err := filter.NewFilter(nil)+ require.NoError(t, err)fi.Opt.MaxSize = 40- defer func() {- fi.Opt.MaxSize = -1- }()+ ctx = filter.ReplaceConfig(ctx, fi)accounting.GlobalStats().ResetCounters()- err := Sync(ctx, r.Fremote, r.Flocal, false)+ err = Sync(ctx, r.Fremote, r.Flocal, false)require.NoError(t, err)fstest.CheckItems(t, r.Fremote, file2, file1)@@ -996,16 +969,14 @@ func TestSyncWithExcludeAndDeleteExcluded(t *testing.T) {fstest.CheckItems(t, r.Fremote, file1, file2, file3)fstest.CheckItems(t, r.Flocal, file1, file2, file3)- fi := filter.GetConfig(ctx)+ fi, err := filter.NewFilter(nil)+ require.NoError(t, err)fi.Opt.MaxSize = 40fi.Opt.DeleteExcluded = true- defer func() {- fi.Opt.MaxSize = -1- fi.Opt.DeleteExcluded = false- }()+ ctx = filter.ReplaceConfig(ctx, fi)accounting.GlobalStats().ResetCounters()- err := Sync(ctx, r.Fremote, r.Flocal, false)+ err = Sync(ctx, r.Fremote, r.Flocal, false)require.NoError(t, err)fstest.CheckItems(t, r.Fremote, file2)@@ -1020,7 +991,7 @@ func TestSyncWithExcludeAndDeleteExcluded(t *testing.T) {// Test with UpdateOlder setfunc TestSyncWithUpdateOlder(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()if fs.GetModifyWindow(ctx, r.Fremote) == fs.ModTimeNotSupported {@@ -1041,12 +1012,7 @@ func TestSyncWithUpdateOlder(t *testing.T) {fstest.CheckItems(t, r.Fremote, oneO, twoO, threeO, fourO)ci.UpdateOlder = true- oldModifyWindow := ci.ModifyWindowci.ModifyWindow = fs.ModTimeNotSupported- defer func() {- ci.UpdateOlder = false- ci.ModifyWindow = oldModifyWindow- }()err := Sync(ctx, r.Fremote, r.Flocal, false)require.NoError(t, err)@@ -1059,7 +1025,6 @@ func TestSyncWithUpdateOlder(t *testing.T) {// now enable checksumci.CheckSum = true- defer func() { ci.CheckSum = false }()err = Sync(ctx, r.Fremote, r.Flocal, false)require.NoError(t, err)@@ -1069,7 +1034,7 @@ func TestSyncWithUpdateOlder(t *testing.T) {// Test with a max transfer durationfunc TestSyncWithMaxDuration(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)if *fstest.RemoteName != "" {t.Skip("Skipping test on non local remote")}@@ -1080,13 +1045,8 @@ func TestSyncWithMaxDuration(t *testing.T) {ci.MaxDuration = maxDurationbytesPerSecond := 300accounting.TokenBucket.SetBwLimit(fs.BwPair{Tx: fs.SizeSuffix(bytesPerSecond), Rx: fs.SizeSuffix(bytesPerSecond)})- oldTransfers := ci.Transfersci.Transfers = 1- defer func() {- ci.MaxDuration = 0 // reset back to default- ci.Transfers = oldTransfers- accounting.TokenBucket.SetBwLimit(fs.BwPair{Tx: -1, Rx: -1})- }()+ defer accounting.TokenBucket.SetBwLimit(fs.BwPair{Tx: -1, Rx: -1})// 5 files of 60 bytes at 60 bytes/s 5 secondstestFiles := make([]fstest.Item, 5)@@ -1114,7 +1074,7 @@ func TestSyncWithMaxDuration(t *testing.T) {// Test with TrackRenames setfunc TestSyncWithTrackRenames(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()@@ -1186,16 +1146,12 @@ func TestRenamesStrategyModtime(t *testing.T) {func TestSyncWithTrackRenamesStrategyModtime(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.TrackRenames = trueci.TrackRenamesStrategy = "modtime"- defer func() {- ci.TrackRenames = false- ci.TrackRenamesStrategy = "hash"- }()canTrackRenames := operations.CanServerSideMove(r.Fremote) && r.Fremote.Precision() != fs.ModTimeNotSupportedt.Logf("Can track renames: %v", canTrackRenames)@@ -1226,16 +1182,12 @@ func TestSyncWithTrackRenamesStrategyModtime(t *testing.T) {func TestSyncWithTrackRenamesStrategyLeaf(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.TrackRenames = trueci.TrackRenamesStrategy = "leaf"- defer func() {- ci.TrackRenames = false- ci.TrackRenamesStrategy = "hash"- }()canTrackRenames := operations.CanServerSideMove(r.Fremote) && r.Fremote.Precision() != fs.ModTimeNotSupportedt.Logf("Can track renames: %v", canTrackRenames)@@ -1274,8 +1226,7 @@ func toyFileTransfers(r *fstest.Run) int64 {}// Test a server-side move if possible, or the backup path if not-func testServerSideMove(t *testing.T, r *fstest.Run, withFilter, testDeleteEmptyDirs bool) {- ctx := context.Background()+func testServerSideMove(ctx context.Context, t *testing.T, r *fstest.Run, withFilter, testDeleteEmptyDirs bool) {FremoteMove, _, finaliseMove, err := fstest.RandomRemote()require.NoError(t, err)defer finaliseMove()@@ -1393,9 +1344,10 @@ func TestMoveWithoutDeleteEmptySrcDirs(t *testing.T) {// Test a server-side move if possible, or the backup path if notfunc TestServerSideMove(t *testing.T) {+ ctx := context.Background()r := fstest.NewRun(t)defer r.Finalise()- testServerSideMove(t, r, false, false)+ testServerSideMove(ctx, t, r, false, false)}// Test a server-side move if possible, or the backup path if not@@ -1404,20 +1356,20 @@ func TestServerSideMoveWithFilter(t *testing.T) {r := fstest.NewRun(t)defer r.Finalise()- fi := filter.GetConfig(ctx)+ fi, err := filter.NewFilter(nil)+ require.NoError(t, err)fi.Opt.MinSize = 40- defer func() {- fi.Opt.MinSize = -1- }()+ ctx = filter.ReplaceConfig(ctx, fi)- testServerSideMove(t, r, true, false)+ testServerSideMove(ctx, t, r, true, false)}// Test a server-side move if possiblefunc TestServerSideMoveDeleteEmptySourceDirs(t *testing.T) {+ ctx := context.Background()r := fstest.NewRun(t)defer r.Finalise()- testServerSideMove(t, r, false, true)+ testServerSideMove(ctx, t, r, false, true)}// Test a server-side move with overlap@@ -1442,11 +1394,11 @@ func TestServerSideMoveOverlap(t *testing.T) {assert.EqualError(t, err, fs.ErrorOverlapping.Error())// Now try with a filter which should also fail with ErrorCantMoveOverlapping- fi := filter.GetConfig(ctx)+ fi, err := filter.NewFilter(nil)+ require.NoError(t, err)fi.Opt.MinSize = 40- defer func() {- fi.Opt.MinSize = -1- }()+ ctx = filter.ReplaceConfig(ctx, fi)+err = MoveDir(ctx, FremoteMove, r.Fremote, false, false)assert.EqualError(t, err, fs.ErrorOverlapping.Error())}@@ -1476,14 +1428,11 @@ func TestSyncOverlap(t *testing.T) {// Test with CompareDest setfunc TestSyncCompareDest(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.CompareDest = []string{r.FremoteName + "/CompareDest"}- defer func() {- ci.CompareDest = []string{}- }()fdst, err := fs.NewFs(ctx, r.FremoteName+"/dst")require.NoError(t, err)@@ -1565,14 +1514,11 @@ func TestSyncCompareDest(t *testing.T) {// Test with multiple CompareDestfunc TestSyncMultipleCompareDest(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.CompareDest = []string{r.FremoteName + "/pre-dest1", r.FremoteName + "/pre-dest2"}- defer func() {- ci.CompareDest = []string{}- }()// check empty dest, new comparefsrc1 := r.WriteFile("1", "1", t1)@@ -1599,7 +1545,7 @@ func TestSyncMultipleCompareDest(t *testing.T) {// Test with CopyDest setfunc TestSyncCopyDest(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()@@ -1608,9 +1554,6 @@ func TestSyncCopyDest(t *testing.T) {}ci.CopyDest = []string{r.FremoteName + "/CopyDest"}- defer func() {- ci.CopyDest = []string{}- }()fdst, err := fs.NewFs(ctx, r.FremoteName+"/dst")require.NoError(t, err)@@ -1704,7 +1647,7 @@ func TestSyncCopyDest(t *testing.T) {// Test with BackupDir setfunc testSyncBackupDir(t *testing.T, backupDir string, suffix string, suffixKeepExtension bool) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()@@ -1729,11 +1672,6 @@ func testSyncBackupDir(t *testing.T, backupDir string, suffix string, suffixKeep}ci.Suffix = suffixci.SuffixKeepExtension = suffixKeepExtension- defer func() {- ci.BackupDir = ""- ci.Suffix = ""- ci.SuffixKeepExtension = false- }()// Make the setup so we have one, two, three in the dest// and one (different), two (same) in the source@@ -1807,7 +1745,7 @@ func TestSyncBackupDirSuffixOnly(t *testing.T) {// Test with Suffix setfunc testSyncSuffix(t *testing.T, suffix string, suffixKeepExtension bool) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()@@ -1818,11 +1756,6 @@ func testSyncSuffix(t *testing.T, suffix string, suffixKeepExtension bool) {ci.Suffix = suffixci.SuffixKeepExtension = suffixKeepExtension- defer func() {- ci.BackupDir = ""- ci.Suffix = ""- ci.SuffixKeepExtension = false- }()// Make the setup so we have one, two, three in the dest// and one (different), two (same) in the source@@ -1931,12 +1864,11 @@ func TestSyncUTFNorm(t *testing.T) {// Test --immutablefunc TestSyncImmutable(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()ci.Immutable = true- defer func() { ci.Immutable = false }()// Create file on sourcefile1 := r.WriteFile("existing", "potato", t1)@@ -1966,7 +1898,7 @@ func TestSyncImmutable(t *testing.T) {// Test --ignore-case-syncfunc TestSyncIgnoreCase(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)+ ctx, ci := fs.AddConfig(ctx)r := fstest.NewRun(t)defer r.Finalise()@@ -1976,7 +1908,6 @@ func TestSyncIgnoreCase(t *testing.T) {}ci.IgnoreCaseSync = true- defer func() { ci.IgnoreCaseSync = false }()// Create files with different filename casingfile1 := r.WriteFile("existing", "potato", t1)@@ -1995,21 +1926,11 @@ func TestSyncIgnoreCase(t *testing.T) {// Test that aborting on --max-transfer worksfunc TestMaxTransfer(t *testing.T) {ctx := context.Background()- ci := fs.GetConfig(ctx)- oldMaxTransfer := ci.MaxTransfer- oldTransfers := ci.Transfers- oldCheckers := ci.Checkers- oldCutoff := ci.CutoffMode+ ctx, ci := fs.AddConfig(ctx)ci.MaxTransfer = 3 * 1024ci.Transfers = 1ci.Checkers = 1ci.CutoffMode = fs.CutoffModeHard- defer func() {- ci.MaxTransfer = oldMaxTransfer- ci.Transfers = oldTransfers- ci.Checkers = oldCheckers- ci.CutoffMode = oldCutoff- }()test := func(t *testing.T, cutoff fs.CutoffMode) {r := fstest.NewRun(t)