Esempio n. 1
0
// Test with BackupDir set
func TestSyncBackupDir(t *testing.T) {
	r := NewRun(t)
	defer r.Finalise()

	if !fs.CanServerSideMove(r.fremote) {
		t.Skip("Skipping test as remote does not support server side move")
	}
	r.Mkdir(r.fremote)

	fs.Config.BackupDir = r.fremoteName + "/backup"
	defer func() {
		fs.Config.BackupDir = ""
	}()

	file1 := r.WriteObject("dst/one", "one", t1)
	file2 := r.WriteObject("dst/two", "two", t2)
	file3 := r.WriteObject("dst/three", "three", t3)
	file2a := r.WriteFile("two", "two", t2)
	file1a := r.WriteFile("one", "oneone", t2)

	fstest.CheckItems(t, r.fremote, file1, file2, file3)
	fstest.CheckItems(t, r.flocal, file1a, file2a)

	fdst, err := fs.NewFs(r.fremoteName + "/dst")
	require.NoError(t, err)

	fs.Stats.ResetCounters()
	err = fs.Sync(fdst, r.flocal)
	require.NoError(t, err)

	// file1 is overwritten and the old version moved to backup-dir
	file1.Path = "backup/one"
	file1a.Path = "dst/one"
	// file 2 is unchanged
	// file 3 is deleted (moved to backup dir)
	file3.Path = "backup/three"

	fstest.CheckItems(t, r.fremote, file1, file2, file3, file1a)

}
Esempio n. 2
0
// Test with TrackRenames set
func TestSyncWithTrackRenames(t *testing.T) {
	r := NewRun(t)
	defer r.Finalise()

	fs.Config.TrackRenames = true
	defer func() {
		fs.Config.TrackRenames = false

	}()

	haveHash := r.fremote.Hashes().Overlap(r.flocal.Hashes()).GetOne() != fs.HashNone
	canTrackRenames := haveHash && fs.CanServerSideMove(r.fremote)
	t.Logf("Can track renames: %v", canTrackRenames)

	f1 := r.WriteFile("potato", "Potato Content", t1)
	f2 := r.WriteFile("yam", "Yam Content", t2)

	fs.Stats.ResetCounters()
	require.NoError(t, fs.Sync(r.fremote, r.flocal))

	fstest.CheckItems(t, r.fremote, f1, f2)
	fstest.CheckItems(t, r.flocal, f1, f2)

	// Now rename locally.
	f2 = r.RenameFile(f2, "yaml")

	fs.Stats.ResetCounters()
	require.NoError(t, fs.Sync(r.fremote, r.flocal))

	fstest.CheckItems(t, r.fremote, f1, f2)

	if canTrackRenames {
		assert.Equal(t, fs.Stats.GetTransfers(), int64(0))
	} else {
		assert.Equal(t, fs.Stats.GetTransfers(), int64(1))
	}
}