2018-10-26 13:48:22 +00:00
|
|
|
package rc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-05-23 11:26:16 +00:00
|
|
|
"github.com/ncw/rclone/fs/cache"
|
2018-10-26 13:48:22 +00:00
|
|
|
"github.com/ncw/rclone/fstest/mockfs"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func mockNewFs(t *testing.T) func() {
|
2019-05-23 11:26:16 +00:00
|
|
|
f := mockfs.NewFs("mock", "mock")
|
|
|
|
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": "/",
|
|
|
|
}
|
|
|
|
f, err := GetFsNamed(in, "potato")
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, f)
|
|
|
|
|
|
|
|
in = Params{
|
|
|
|
"sausage": "/",
|
|
|
|
}
|
|
|
|
f, err = GetFsNamed(in, "potato")
|
|
|
|
require.Error(t, err)
|
|
|
|
assert.Nil(t, f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetFs(t *testing.T) {
|
|
|
|
defer mockNewFs(t)()
|
|
|
|
|
|
|
|
in := Params{
|
|
|
|
"fs": "/",
|
|
|
|
}
|
|
|
|
f, err := GetFs(in)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetFsAndRemoteNamed(t *testing.T) {
|
|
|
|
defer mockNewFs(t)()
|
|
|
|
|
|
|
|
in := Params{
|
|
|
|
"fs": "/",
|
|
|
|
"remote": "hello",
|
|
|
|
}
|
|
|
|
f, remote, err := GetFsAndRemoteNamed(in, "fs", "remote")
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, f)
|
|
|
|
assert.Equal(t, "hello", remote)
|
|
|
|
|
2019-01-11 17:00:59 +00:00
|
|
|
f, _, err = GetFsAndRemoteNamed(in, "fsX", "remote")
|
2018-10-26 13:48:22 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
assert.Nil(t, f)
|
|
|
|
|
2019-01-11 17:00:59 +00:00
|
|
|
f, _, err = GetFsAndRemoteNamed(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",
|
|
|
|
}
|
|
|
|
f, remote, err := GetFsAndRemote(in)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, f)
|
|
|
|
assert.Equal(t, "hello", remote)
|
|
|
|
}
|