forked from rclone/rclone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrc_test.go
127 lines (109 loc) · 3.17 KB
/
rc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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, call *rc.Call) {
if *fstest.RemoteName != "" {
t.Skip("Skipping test on non local remote")
}
r, vfs = newTestVFS(t)
call = rc.Calls.Get(method)
assert.NotNil(t, call)
return r, vfs, 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 := newTestVFS(t)
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.Opt
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)
inPresent = rc.Params{"fs": fs.ConfigString(r.Fremote)}
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, call := rcNewRun(t, "vfs/forget")
_, _ = r, vfs
in := rc.Params{"fs": fs.ConfigString(r.Fremote)}
out, err := call.Fn(context.Background(), in)
require.NoError(t, err)
assert.Equal(t, rc.Params{
"forgotten": []string{},
}, out)
// FIXME needs more tests
}
func TestRcRefresh(t *testing.T) {
r, vfs, call := rcNewRun(t, "vfs/refresh")
_, _ = r, vfs
in := rc.Params{"fs": fs.ConfigString(r.Fremote)}
out, err := call.Fn(context.Background(), in)
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, call := rcNewRun(t, "vfs/poll-interval")
_ = 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, call := rcNewRun(t, "vfs/list")
_ = vfs
out, err := call.Fn(context.Background(), nil)
require.NoError(t, err)
assert.Equal(t, rc.Params{
"vfses": []string{
fs.ConfigString(r.Fremote),
},
}, out)
}
func TestRcStats(t *testing.T) {
r, vfs, call := rcNewRun(t, "vfs/stats")
out, err := call.Fn(context.Background(), nil)
require.NoError(t, err)
assert.Equal(t, fs.ConfigString(r.Fremote), out["fs"])
assert.Equal(t, int32(1), out["inUse"])
assert.Equal(t, 0, out["metadataCache"].(rc.Params)["files"])
assert.Equal(t, 1, out["metadataCache"].(rc.Params)["dirs"])
assert.Equal(t, vfs.Opt, out["opt"].(vfscommon.Options))
}