mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 15:38:57 +01:00
7781ea8d59
Before this change we initialized the rc for a single VFS. However rclone can have multiple VFSes in use now so this is no longer adequate. This change adds an optional fs parameter to all the VFS methods to disambiguate VFSes when there is more than one in use. It also adds a method vfs/list to show all the active VFSes. This adds outline tests for the rc commands which didn't have tests before.
119 lines
2.8 KiB
Go
119 lines
2.8 KiB
Go
package vfs
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
"github.com/rclone/rclone/fs/rc"
|
|
"github.com/rclone/rclone/fstest"
|
|
"github.com/rclone/rclone/vfs/vfscommon"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func rcNewRun(t *testing.T, method string) (r *fstest.Run, vfs *VFS, cleanup func(), call *rc.Call) {
|
|
if *fstest.RemoteName != "" {
|
|
t.Skip("Skipping test on non local remote")
|
|
}
|
|
r, vfs, cleanup = newTestVFS(t)
|
|
call = rc.Calls.Get(method)
|
|
assert.NotNil(t, call)
|
|
return r, vfs, cleanup, call
|
|
}
|
|
|
|
func TestRcGetVFS(t *testing.T) {
|
|
in := rc.Params{}
|
|
vfs, err := getVFS(in)
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "no VFS active")
|
|
assert.Nil(t, vfs)
|
|
|
|
r, vfs2, cleanup := newTestVFS(t)
|
|
defer cleanup()
|
|
|
|
vfs, err = getVFS(in)
|
|
require.NoError(t, err)
|
|
assert.True(t, vfs == vfs2)
|
|
|
|
inPresent := rc.Params{"fs": fs.ConfigString(r.Fremote)}
|
|
vfs, err = getVFS(inPresent)
|
|
require.NoError(t, err)
|
|
assert.True(t, vfs == vfs2)
|
|
|
|
inWrong := rc.Params{"fs": fs.ConfigString(r.Fremote) + "notfound"}
|
|
vfs, err = getVFS(inWrong)
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "no VFS found with name")
|
|
assert.Nil(t, vfs)
|
|
|
|
opt := vfscommon.DefaultOpt
|
|
opt.NoModTime = true
|
|
vfs3 := New(r.Fremote, &opt)
|
|
defer vfs3.Shutdown()
|
|
|
|
vfs, err = getVFS(in)
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "more than one VFS active - need")
|
|
assert.Nil(t, vfs)
|
|
|
|
vfs, err = getVFS(inPresent)
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "more than one VFS active with name")
|
|
assert.Nil(t, vfs)
|
|
}
|
|
|
|
func TestRcForget(t *testing.T) {
|
|
r, vfs, cleanup, call := rcNewRun(t, "vfs/forget")
|
|
defer cleanup()
|
|
_, _ = r, vfs
|
|
out, err := call.Fn(context.Background(), nil)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, rc.Params{
|
|
"forgotten": []string{},
|
|
}, out)
|
|
// FIXME needs more tests
|
|
}
|
|
|
|
func TestRcRefresh(t *testing.T) {
|
|
r, vfs, cleanup, call := rcNewRun(t, "vfs/refresh")
|
|
defer cleanup()
|
|
_, _ = r, vfs
|
|
out, err := call.Fn(context.Background(), nil)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, rc.Params{
|
|
"result": map[string]string{
|
|
"": "OK",
|
|
},
|
|
}, out)
|
|
// FIXME needs more tests
|
|
}
|
|
|
|
func TestRcPollInterval(t *testing.T) {
|
|
r, vfs, cleanup, call := rcNewRun(t, "vfs/poll-interval")
|
|
defer cleanup()
|
|
_ = vfs
|
|
if r.Fremote.Features().ChangeNotify == nil {
|
|
t.Skip("ChangeNotify not supported")
|
|
}
|
|
out, err := call.Fn(context.Background(), nil)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, rc.Params{}, out)
|
|
// FIXME needs more tests
|
|
}
|
|
|
|
func TestRcList(t *testing.T) {
|
|
r, vfs, cleanup, call := rcNewRun(t, "vfs/list")
|
|
defer cleanup()
|
|
_ = vfs
|
|
|
|
out, err := call.Fn(context.Background(), nil)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, rc.Params{
|
|
"vfses": []string{
|
|
fs.ConfigString(r.Fremote),
|
|
},
|
|
}, out)
|
|
}
|