2018-10-26 21:48:22 +08:00
|
|
|
package rc
|
|
|
|
|
|
|
|
import (
|
2019-06-17 16:34:30 +08:00
|
|
|
"context"
|
2018-11-05 00:16:43 +08:00
|
|
|
"runtime"
|
2018-10-26 21:48:22 +08:00
|
|
|
"testing"
|
|
|
|
|
2019-10-17 22:04:22 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fs/config/obscure"
|
|
|
|
"github.com/rclone/rclone/fs/version"
|
2018-10-26 21:48:22 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestInternalNoop(t *testing.T) {
|
|
|
|
call := Calls.Get("rc/noop")
|
|
|
|
assert.NotNil(t, call)
|
|
|
|
in := Params{
|
|
|
|
"String": "hello",
|
|
|
|
"Int": 42,
|
|
|
|
}
|
2019-06-17 16:34:30 +08:00
|
|
|
out, err := call.Fn(context.Background(), in)
|
2018-10-26 21:48:22 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, out)
|
|
|
|
assert.Equal(t, in, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInternalError(t *testing.T) {
|
|
|
|
call := Calls.Get("rc/error")
|
|
|
|
assert.NotNil(t, call)
|
|
|
|
in := Params{}
|
2019-06-17 16:34:30 +08:00
|
|
|
out, err := call.Fn(context.Background(), in)
|
2018-10-26 21:48:22 +08:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInternalList(t *testing.T) {
|
|
|
|
call := Calls.Get("rc/list")
|
|
|
|
assert.NotNil(t, call)
|
|
|
|
in := Params{}
|
2019-06-17 16:34:30 +08:00
|
|
|
out, err := call.Fn(context.Background(), in)
|
2018-10-26 21:48:22 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, out)
|
|
|
|
assert.Equal(t, Params{"commands": Calls.List()}, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCorePid(t *testing.T) {
|
|
|
|
call := Calls.Get("core/pid")
|
|
|
|
assert.NotNil(t, call)
|
|
|
|
in := Params{}
|
2019-06-17 16:34:30 +08:00
|
|
|
out, err := call.Fn(context.Background(), in)
|
2018-10-26 21:48:22 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, out)
|
|
|
|
pid := out["pid"]
|
|
|
|
assert.NotEqual(t, nil, pid)
|
|
|
|
_, ok := pid.(int)
|
|
|
|
assert.Equal(t, true, ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCoreMemstats(t *testing.T) {
|
|
|
|
call := Calls.Get("core/memstats")
|
|
|
|
assert.NotNil(t, call)
|
|
|
|
in := Params{}
|
2019-06-17 16:34:30 +08:00
|
|
|
out, err := call.Fn(context.Background(), in)
|
2018-10-26 21:48:22 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, out)
|
|
|
|
sys := out["Sys"]
|
|
|
|
assert.NotEqual(t, nil, sys)
|
|
|
|
_, ok := sys.(uint64)
|
|
|
|
assert.Equal(t, true, ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCoreGC(t *testing.T) {
|
|
|
|
call := Calls.Get("core/gc")
|
|
|
|
assert.NotNil(t, call)
|
|
|
|
in := Params{}
|
2019-06-17 16:34:30 +08:00
|
|
|
out, err := call.Fn(context.Background(), in)
|
2018-10-26 21:48:22 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, out)
|
|
|
|
assert.Equal(t, Params(nil), out)
|
|
|
|
}
|
2018-11-05 00:16:43 +08:00
|
|
|
|
|
|
|
func TestCoreVersion(t *testing.T) {
|
|
|
|
call := Calls.Get("core/version")
|
|
|
|
assert.NotNil(t, call)
|
|
|
|
in := Params{}
|
2019-06-17 16:34:30 +08:00
|
|
|
out, err := call.Fn(context.Background(), in)
|
2018-11-05 00:16:43 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, out)
|
|
|
|
assert.Equal(t, fs.Version, out["version"])
|
|
|
|
assert.Equal(t, runtime.GOOS, out["os"])
|
|
|
|
assert.Equal(t, runtime.GOARCH, out["arch"])
|
|
|
|
assert.Equal(t, runtime.Version(), out["goVersion"])
|
|
|
|
_ = out["isGit"].(bool)
|
|
|
|
v := out["decomposed"].(version.Version)
|
|
|
|
assert.True(t, len(v) >= 2)
|
|
|
|
}
|
2018-11-05 00:30:56 +08:00
|
|
|
|
|
|
|
func TestCoreObscure(t *testing.T) {
|
|
|
|
call := Calls.Get("core/obscure")
|
|
|
|
assert.NotNil(t, call)
|
|
|
|
in := Params{
|
|
|
|
"clear": "potato",
|
|
|
|
}
|
2019-06-17 16:34:30 +08:00
|
|
|
out, err := call.Fn(context.Background(), in)
|
2018-11-05 00:30:56 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, out)
|
|
|
|
assert.Equal(t, in["clear"], obscure.MustReveal(out["obscured"].(string)))
|
|
|
|
}
|
2019-10-17 22:04:22 +08:00
|
|
|
|
|
|
|
func TestCoreQuit(t *testing.T) {
|
|
|
|
//The call should return an error if param exitCode is not parsed to int
|
|
|
|
call := Calls.Get("core/quit")
|
|
|
|
assert.NotNil(t, call)
|
|
|
|
in := Params{
|
|
|
|
"exitCode": "potato",
|
|
|
|
}
|
|
|
|
_, err := call.Fn(context.Background(), in)
|
|
|
|
require.Error(t, err)
|
|
|
|
}
|