2018-10-26 20:52:27 +02:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
2019-06-17 10:34:30 +02:00
|
|
|
"context"
|
2018-10-26 20:52:27 +02:00
|
|
|
"testing"
|
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/fs/cache"
|
|
|
|
"github.com/rclone/rclone/fs/rc"
|
|
|
|
"github.com/rclone/rclone/fstest"
|
2018-10-26 20:52:27 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func rcNewRun(t *testing.T, method string) (*fstest.Run, *rc.Call) {
|
|
|
|
if *fstest.RemoteName != "" {
|
|
|
|
t.Skip("Skipping test on non local remote")
|
|
|
|
}
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
call := rc.Calls.Get(method)
|
|
|
|
assert.NotNil(t, call)
|
2019-05-23 13:26:16 +02:00
|
|
|
cache.Put(r.LocalName, r.Flocal)
|
|
|
|
cache.Put(r.FremoteName, r.Fremote)
|
2018-10-26 20:52:27 +02:00
|
|
|
return r, call
|
|
|
|
}
|
|
|
|
|
|
|
|
// sync/copy: copy a directory from source remote to destination remote
|
|
|
|
func TestRcCopy(t *testing.T) {
|
|
|
|
r, call := rcNewRun(t, "sync/copy")
|
|
|
|
defer r.Finalise()
|
2019-06-17 10:34:30 +02:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2018-10-26 20:52:27 +02:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteBoth(context.Background(), "file1", "file1 contents", t1)
|
2018-10-26 20:52:27 +02:00
|
|
|
file2 := r.WriteFile("subdir/file2", "file2 contents", t2)
|
2019-06-17 10:34:30 +02:00
|
|
|
file3 := r.WriteObject(context.Background(), "subdir/subsubdir/file3", "file3 contents", t3)
|
2018-10-26 20:52:27 +02:00
|
|
|
|
2021-11-09 12:43:36 +01:00
|
|
|
r.CheckLocalItems(t, file1, file2)
|
|
|
|
r.CheckRemoteItems(t, file1, file3)
|
2018-10-26 20:52:27 +02:00
|
|
|
|
|
|
|
in := rc.Params{
|
|
|
|
"srcFs": r.LocalName,
|
|
|
|
"dstFs": r.FremoteName,
|
|
|
|
}
|
2019-06-17 10:34:30 +02:00
|
|
|
out, err := call.Fn(context.Background(), in)
|
2018-10-26 20:52:27 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, rc.Params(nil), out)
|
|
|
|
|
2021-11-09 12:43:36 +01:00
|
|
|
r.CheckLocalItems(t, file1, file2)
|
|
|
|
r.CheckRemoteItems(t, file1, file2, file3)
|
2018-10-26 20:52:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// sync/move: move a directory from source remote to destination remote
|
|
|
|
func TestRcMove(t *testing.T) {
|
|
|
|
r, call := rcNewRun(t, "sync/move")
|
|
|
|
defer r.Finalise()
|
2019-06-17 10:34:30 +02:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2018-10-26 20:52:27 +02:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteBoth(context.Background(), "file1", "file1 contents", t1)
|
2018-10-26 20:52:27 +02:00
|
|
|
file2 := r.WriteFile("subdir/file2", "file2 contents", t2)
|
2019-06-17 10:34:30 +02:00
|
|
|
file3 := r.WriteObject(context.Background(), "subdir/subsubdir/file3", "file3 contents", t3)
|
2018-10-26 20:52:27 +02:00
|
|
|
|
2021-11-09 12:43:36 +01:00
|
|
|
r.CheckLocalItems(t, file1, file2)
|
|
|
|
r.CheckRemoteItems(t, file1, file3)
|
2018-10-26 20:52:27 +02:00
|
|
|
|
|
|
|
in := rc.Params{
|
|
|
|
"srcFs": r.LocalName,
|
|
|
|
"dstFs": r.FremoteName,
|
|
|
|
}
|
2019-06-17 10:34:30 +02:00
|
|
|
out, err := call.Fn(context.Background(), in)
|
2018-10-26 20:52:27 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, rc.Params(nil), out)
|
|
|
|
|
2021-11-09 12:43:36 +01:00
|
|
|
r.CheckLocalItems(t)
|
|
|
|
r.CheckRemoteItems(t, file1, file2, file3)
|
2018-10-26 20:52:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// sync/sync: sync a directory from source remote to destination remote
|
|
|
|
func TestRcSync(t *testing.T) {
|
|
|
|
r, call := rcNewRun(t, "sync/sync")
|
|
|
|
defer r.Finalise()
|
2019-06-17 10:34:30 +02:00
|
|
|
r.Mkdir(context.Background(), r.Fremote)
|
2018-10-26 20:52:27 +02:00
|
|
|
|
2019-06-17 10:34:30 +02:00
|
|
|
file1 := r.WriteBoth(context.Background(), "file1", "file1 contents", t1)
|
2018-10-26 20:52:27 +02:00
|
|
|
file2 := r.WriteFile("subdir/file2", "file2 contents", t2)
|
2019-06-17 10:34:30 +02:00
|
|
|
file3 := r.WriteObject(context.Background(), "subdir/subsubdir/file3", "file3 contents", t3)
|
2018-10-26 20:52:27 +02:00
|
|
|
|
2021-11-09 12:43:36 +01:00
|
|
|
r.CheckLocalItems(t, file1, file2)
|
|
|
|
r.CheckRemoteItems(t, file1, file3)
|
2018-10-26 20:52:27 +02:00
|
|
|
|
|
|
|
in := rc.Params{
|
|
|
|
"srcFs": r.LocalName,
|
|
|
|
"dstFs": r.FremoteName,
|
|
|
|
}
|
2019-06-17 10:34:30 +02:00
|
|
|
out, err := call.Fn(context.Background(), in)
|
2018-10-26 20:52:27 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, rc.Params(nil), out)
|
|
|
|
|
2021-11-09 12:43:36 +01:00
|
|
|
r.CheckLocalItems(t, file1, file2)
|
|
|
|
r.CheckRemoteItems(t, file1, file2)
|
2018-10-26 20:52:27 +02:00
|
|
|
}
|