Implement --compare-dest & --copy-dest Fixes #3278
This commit is contained in:
parent
266600dba7
commit
8e8b78d7e5
7 changed files with 601 additions and 47 deletions
|
@ -1216,6 +1216,196 @@ func TestSyncOverlap(t *testing.T) {
|
|||
checkErr(Sync(context.Background(), FremoteSync, FremoteSync, false))
|
||||
}
|
||||
|
||||
// Test with CompareDest set
|
||||
func TestSyncCompareDest(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
|
||||
fs.Config.CompareDest = r.FremoteName + "/CompareDest"
|
||||
defer func() {
|
||||
fs.Config.CompareDest = ""
|
||||
}()
|
||||
|
||||
fdst, err := fs.NewFs(r.FremoteName + "/dst")
|
||||
require.NoError(t, err)
|
||||
|
||||
// check empty dest, empty compare
|
||||
file1 := r.WriteFile("one", "one", t1)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
file1dst := file1
|
||||
file1dst.Path = "dst/one"
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file1dst)
|
||||
|
||||
// check old dest, empty compare
|
||||
file1b := r.WriteFile("one", "onet2", t2)
|
||||
fstest.CheckItems(t, r.Fremote, file1dst)
|
||||
fstest.CheckItems(t, r.Flocal, file1b)
|
||||
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
file1bdst := file1b
|
||||
file1bdst.Path = "dst/one"
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file1bdst)
|
||||
|
||||
// check old dest, new compare
|
||||
file3 := r.WriteObject(context.Background(), "dst/one", "one", t1)
|
||||
file2 := r.WriteObject(context.Background(), "CompareDest/one", "onet2", t2)
|
||||
file1c := r.WriteFile("one", "onet2", t2)
|
||||
fstest.CheckItems(t, r.Fremote, file2, file3)
|
||||
fstest.CheckItems(t, r.Flocal, file1c)
|
||||
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file2, file3)
|
||||
|
||||
// check empty dest, new compare
|
||||
file4 := r.WriteObject(context.Background(), "CompareDest/two", "two", t2)
|
||||
file5 := r.WriteFile("two", "two", t2)
|
||||
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
||||
fstest.CheckItems(t, r.Flocal, file1c, file5)
|
||||
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
||||
|
||||
// check new dest, new compare
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
||||
|
||||
// check empty dest, old compare
|
||||
file5b := r.WriteFile("two", "twot3", t3)
|
||||
fstest.CheckItems(t, r.Fremote, file2, file3, file4)
|
||||
fstest.CheckItems(t, r.Flocal, file1c, file5b)
|
||||
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
file5bdst := file5b
|
||||
file5bdst.Path = "dst/two"
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file2, file3, file4, file5bdst)
|
||||
}
|
||||
|
||||
// Test with CopyDest set
|
||||
func TestSyncCopyDest(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
defer r.Finalise()
|
||||
|
||||
if r.Fremote.Features().Copy == nil {
|
||||
t.Skip("Skipping test as remote does not support server side copy")
|
||||
}
|
||||
|
||||
fs.Config.CopyDest = r.FremoteName + "/CopyDest"
|
||||
defer func() {
|
||||
fs.Config.CopyDest = ""
|
||||
}()
|
||||
|
||||
fdst, err := fs.NewFs(r.FremoteName + "/dst")
|
||||
require.NoError(t, err)
|
||||
|
||||
// check empty dest, empty copy
|
||||
file1 := r.WriteFile("one", "one", t1)
|
||||
fstest.CheckItems(t, r.Flocal, file1)
|
||||
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
file1dst := file1
|
||||
file1dst.Path = "dst/one"
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file1dst)
|
||||
|
||||
// check old dest, empty copy
|
||||
file1b := r.WriteFile("one", "onet2", t2)
|
||||
fstest.CheckItems(t, r.Fremote, file1dst)
|
||||
fstest.CheckItems(t, r.Flocal, file1b)
|
||||
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
file1bdst := file1b
|
||||
file1bdst.Path = "dst/one"
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file1bdst)
|
||||
|
||||
// check old dest, new copy, backup-dir
|
||||
|
||||
fs.Config.BackupDir = r.FremoteName + "/BackupDir"
|
||||
|
||||
file3 := r.WriteObject(context.Background(), "dst/one", "one", t1)
|
||||
file2 := r.WriteObject(context.Background(), "CopyDest/one", "onet2", t2)
|
||||
file1c := r.WriteFile("one", "onet2", t2)
|
||||
fstest.CheckItems(t, r.Fremote, file2, file3)
|
||||
fstest.CheckItems(t, r.Flocal, file1c)
|
||||
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
file2dst := file2
|
||||
file2dst.Path = "dst/one"
|
||||
file3.Path = "BackupDir/one"
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3)
|
||||
fs.Config.BackupDir = ""
|
||||
|
||||
// check empty dest, new copy
|
||||
file4 := r.WriteObject(context.Background(), "CopyDest/two", "two", t2)
|
||||
file5 := r.WriteFile("two", "two", t2)
|
||||
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4)
|
||||
fstest.CheckItems(t, r.Flocal, file1c, file5)
|
||||
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
file4dst := file4
|
||||
file4dst.Path = "dst/two"
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst)
|
||||
|
||||
// check new dest, new copy
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst)
|
||||
|
||||
// check empty dest, old copy
|
||||
file6 := r.WriteObject(context.Background(), "CopyDest/three", "three", t2)
|
||||
file7 := r.WriteFile("three", "threet3", t3)
|
||||
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst, file6)
|
||||
fstest.CheckItems(t, r.Flocal, file1c, file5, file7)
|
||||
|
||||
accounting.Stats.ResetCounters()
|
||||
err = Sync(context.Background(), fdst, r.Flocal, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
file7dst := file7
|
||||
file7dst.Path = "dst/three"
|
||||
|
||||
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst, file6, file7dst)
|
||||
}
|
||||
|
||||
// Test with BackupDir set
|
||||
func testSyncBackupDir(t *testing.T, suffix string, suffixKeepExtension bool) {
|
||||
r := fstest.NewRun(t)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue