2018-10-26 13:48:22 +00:00
|
|
|
package rc
|
|
|
|
|
|
|
|
import (
|
2020-11-05 15:18:51 +00:00
|
|
|
"context"
|
2018-10-26 13:48:22 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs/cache"
|
|
|
|
"github.com/rclone/rclone/fstest/mockfs"
|
2018-10-26 13:48:22 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func mockNewFs(t *testing.T) func() {
|
2020-11-05 16:00:08 +00:00
|
|
|
f := mockfs.NewFs(context.Background(), "mock", "mock")
|
2019-05-23 11:26:16 +00:00
|
|
|
cache.Put("/", f)
|
2018-10-26 13:48:22 +00:00
|
|
|
return func() {
|
2019-05-23 11:26:16 +00:00
|
|
|
cache.Clear()
|
2018-10-26 13:48:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetFsNamed(t *testing.T) {
|
|
|
|
defer mockNewFs(t)()
|
|
|
|
|
|
|
|
in := Params{
|
|
|
|
"potato": "/",
|
|
|
|
}
|
2020-11-05 15:18:51 +00:00
|
|
|
f, err := GetFsNamed(context.Background(), in, "potato")
|
2018-10-26 13:48:22 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, f)
|
|
|
|
|
|
|
|
in = Params{
|
|
|
|
"sausage": "/",
|
|
|
|
}
|
2020-11-05 15:18:51 +00:00
|
|
|
f, err = GetFsNamed(context.Background(), in, "potato")
|
2018-10-26 13:48:22 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
assert.Nil(t, f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetFs(t *testing.T) {
|
|
|
|
defer mockNewFs(t)()
|
|
|
|
|
|
|
|
in := Params{
|
|
|
|
"fs": "/",
|
|
|
|
}
|
2020-11-05 15:18:51 +00:00
|
|
|
f, err := GetFs(context.Background(), in)
|
2018-10-26 13:48:22 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetFsAndRemoteNamed(t *testing.T) {
|
|
|
|
defer mockNewFs(t)()
|
|
|
|
|
|
|
|
in := Params{
|
|
|
|
"fs": "/",
|
|
|
|
"remote": "hello",
|
|
|
|
}
|
2020-11-05 15:18:51 +00:00
|
|
|
f, remote, err := GetFsAndRemoteNamed(context.Background(), in, "fs", "remote")
|
2018-10-26 13:48:22 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, f)
|
|
|
|
assert.Equal(t, "hello", remote)
|
|
|
|
|
2020-11-05 15:18:51 +00:00
|
|
|
f, _, err = GetFsAndRemoteNamed(context.Background(), in, "fsX", "remote")
|
2018-10-26 13:48:22 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
assert.Nil(t, f)
|
|
|
|
|
2020-11-05 15:18:51 +00:00
|
|
|
f, _, err = GetFsAndRemoteNamed(context.Background(), in, "fs", "remoteX")
|
2018-10-26 13:48:22 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
assert.Nil(t, f)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetFsAndRemote(t *testing.T) {
|
|
|
|
defer mockNewFs(t)()
|
|
|
|
|
|
|
|
in := Params{
|
|
|
|
"fs": "/",
|
|
|
|
"remote": "hello",
|
|
|
|
}
|
2020-11-05 15:18:51 +00:00
|
|
|
f, remote, err := GetFsAndRemote(context.Background(), in)
|
2018-10-26 13:48:22 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, f)
|
|
|
|
assert.Equal(t, "hello", remote)
|
|
|
|
}
|