2018-08-18 08:39:49 +08:00
|
|
|
// Test Union filesystem interface
|
|
|
|
package union_test
|
|
|
|
|
|
|
|
import (
|
2021-01-15 20:18:28 +08:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2019-11-30 22:41:39 +08:00
|
|
|
"os"
|
2018-08-18 08:39:49 +08:00
|
|
|
"testing"
|
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
_ "github.com/rclone/rclone/backend/local"
|
2019-11-30 22:41:39 +08:00
|
|
|
"github.com/rclone/rclone/fstest"
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/fstest/fstests"
|
2021-01-15 20:18:28 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-11-30 22:41:39 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-08-18 08:39:49 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestIntegration runs integration tests against the remote
|
|
|
|
func TestIntegration(t *testing.T) {
|
2019-11-30 22:41:39 +08:00
|
|
|
if *fstest.RemoteName == "" {
|
|
|
|
t.Skip("Skipping as -remote not set")
|
|
|
|
}
|
2018-08-18 08:39:49 +08:00
|
|
|
fstests.Run(t, &fstests.Opt{
|
2019-11-30 22:41:39 +08:00
|
|
|
RemoteName: *fstest.RemoteName,
|
|
|
|
UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"},
|
|
|
|
UnimplementableObjectMethods: []string{"MimeType"},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-15 20:18:28 +08:00
|
|
|
func makeTestDirs(t *testing.T, n int) (dirs []string, clean func()) {
|
|
|
|
for i := 1; i <= n; i++ {
|
|
|
|
dir, err := ioutil.TempDir("", fmt.Sprintf("rclone-union-test-%d", n))
|
|
|
|
require.NoError(t, err)
|
|
|
|
dirs = append(dirs, dir)
|
|
|
|
}
|
|
|
|
clean = func() {
|
|
|
|
for _, dir := range dirs {
|
|
|
|
err := os.RemoveAll(dir)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dirs, clean
|
|
|
|
}
|
|
|
|
|
2019-11-30 22:41:39 +08:00
|
|
|
func TestStandard(t *testing.T) {
|
|
|
|
if *fstest.RemoteName != "" {
|
|
|
|
t.Skip("Skipping as -remote set")
|
|
|
|
}
|
2021-01-15 20:18:28 +08:00
|
|
|
dirs, clean := makeTestDirs(t, 3)
|
|
|
|
defer clean()
|
|
|
|
upstreams := dirs[0] + " " + dirs[1] + " " + dirs[2]
|
2019-11-30 22:41:39 +08:00
|
|
|
name := "TestUnion"
|
|
|
|
fstests.Run(t, &fstests.Opt{
|
|
|
|
RemoteName: name + ":",
|
|
|
|
ExtraConfig: []fstests.ExtraConfigItem{
|
|
|
|
{Name: name, Key: "type", Value: "union"},
|
|
|
|
{Name: name, Key: "upstreams", Value: upstreams},
|
|
|
|
{Name: name, Key: "action_policy", Value: "epall"},
|
|
|
|
{Name: name, Key: "create_policy", Value: "epmfs"},
|
|
|
|
{Name: name, Key: "search_policy", Value: "ff"},
|
|
|
|
},
|
|
|
|
UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"},
|
|
|
|
UnimplementableObjectMethods: []string{"MimeType"},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRO(t *testing.T) {
|
|
|
|
if *fstest.RemoteName != "" {
|
|
|
|
t.Skip("Skipping as -remote set")
|
|
|
|
}
|
2021-01-15 20:18:28 +08:00
|
|
|
dirs, clean := makeTestDirs(t, 3)
|
|
|
|
defer clean()
|
|
|
|
upstreams := dirs[0] + " " + dirs[1] + ":ro " + dirs[2] + ":ro"
|
2019-11-30 22:41:39 +08:00
|
|
|
name := "TestUnionRO"
|
|
|
|
fstests.Run(t, &fstests.Opt{
|
|
|
|
RemoteName: name + ":",
|
|
|
|
ExtraConfig: []fstests.ExtraConfigItem{
|
|
|
|
{Name: name, Key: "type", Value: "union"},
|
|
|
|
{Name: name, Key: "upstreams", Value: upstreams},
|
|
|
|
{Name: name, Key: "action_policy", Value: "epall"},
|
|
|
|
{Name: name, Key: "create_policy", Value: "epmfs"},
|
|
|
|
{Name: name, Key: "search_policy", Value: "ff"},
|
|
|
|
},
|
|
|
|
UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"},
|
|
|
|
UnimplementableObjectMethods: []string{"MimeType"},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNC(t *testing.T) {
|
|
|
|
if *fstest.RemoteName != "" {
|
|
|
|
t.Skip("Skipping as -remote set")
|
|
|
|
}
|
2021-01-15 20:18:28 +08:00
|
|
|
dirs, clean := makeTestDirs(t, 3)
|
|
|
|
defer clean()
|
|
|
|
upstreams := dirs[0] + " " + dirs[1] + ":nc " + dirs[2] + ":nc"
|
2019-11-30 22:41:39 +08:00
|
|
|
name := "TestUnionNC"
|
|
|
|
fstests.Run(t, &fstests.Opt{
|
|
|
|
RemoteName: name + ":",
|
|
|
|
ExtraConfig: []fstests.ExtraConfigItem{
|
|
|
|
{Name: name, Key: "type", Value: "union"},
|
|
|
|
{Name: name, Key: "upstreams", Value: upstreams},
|
|
|
|
{Name: name, Key: "action_policy", Value: "epall"},
|
|
|
|
{Name: name, Key: "create_policy", Value: "epmfs"},
|
|
|
|
{Name: name, Key: "search_policy", Value: "ff"},
|
|
|
|
},
|
|
|
|
UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"},
|
|
|
|
UnimplementableObjectMethods: []string{"MimeType"},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPolicy1(t *testing.T) {
|
|
|
|
if *fstest.RemoteName != "" {
|
|
|
|
t.Skip("Skipping as -remote set")
|
|
|
|
}
|
2021-01-15 20:18:28 +08:00
|
|
|
dirs, clean := makeTestDirs(t, 3)
|
|
|
|
defer clean()
|
|
|
|
upstreams := dirs[0] + " " + dirs[1] + " " + dirs[2]
|
2019-11-30 22:41:39 +08:00
|
|
|
name := "TestUnionPolicy1"
|
|
|
|
fstests.Run(t, &fstests.Opt{
|
|
|
|
RemoteName: name + ":",
|
|
|
|
ExtraConfig: []fstests.ExtraConfigItem{
|
|
|
|
{Name: name, Key: "type", Value: "union"},
|
|
|
|
{Name: name, Key: "upstreams", Value: upstreams},
|
|
|
|
{Name: name, Key: "action_policy", Value: "all"},
|
|
|
|
{Name: name, Key: "create_policy", Value: "lus"},
|
|
|
|
{Name: name, Key: "search_policy", Value: "all"},
|
|
|
|
},
|
|
|
|
UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"},
|
|
|
|
UnimplementableObjectMethods: []string{"MimeType"},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPolicy2(t *testing.T) {
|
|
|
|
if *fstest.RemoteName != "" {
|
|
|
|
t.Skip("Skipping as -remote set")
|
|
|
|
}
|
2021-01-15 20:18:28 +08:00
|
|
|
dirs, clean := makeTestDirs(t, 3)
|
|
|
|
defer clean()
|
|
|
|
upstreams := dirs[0] + " " + dirs[1] + " " + dirs[2]
|
2019-11-30 22:41:39 +08:00
|
|
|
name := "TestUnionPolicy2"
|
|
|
|
fstests.Run(t, &fstests.Opt{
|
|
|
|
RemoteName: name + ":",
|
|
|
|
ExtraConfig: []fstests.ExtraConfigItem{
|
|
|
|
{Name: name, Key: "type", Value: "union"},
|
|
|
|
{Name: name, Key: "upstreams", Value: upstreams},
|
|
|
|
{Name: name, Key: "action_policy", Value: "all"},
|
|
|
|
{Name: name, Key: "create_policy", Value: "rand"},
|
|
|
|
{Name: name, Key: "search_policy", Value: "ff"},
|
|
|
|
},
|
|
|
|
UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"},
|
|
|
|
UnimplementableObjectMethods: []string{"MimeType"},
|
2018-08-18 08:39:49 +08:00
|
|
|
})
|
|
|
|
}
|
2020-08-31 01:30:45 +08:00
|
|
|
|
|
|
|
func TestPolicy3(t *testing.T) {
|
|
|
|
if *fstest.RemoteName != "" {
|
|
|
|
t.Skip("Skipping as -remote set")
|
|
|
|
}
|
2021-01-15 20:18:28 +08:00
|
|
|
dirs, clean := makeTestDirs(t, 3)
|
|
|
|
defer clean()
|
|
|
|
upstreams := dirs[0] + " " + dirs[1] + " " + dirs[2]
|
2020-08-31 01:30:45 +08:00
|
|
|
name := "TestUnionPolicy3"
|
|
|
|
fstests.Run(t, &fstests.Opt{
|
|
|
|
RemoteName: name + ":",
|
|
|
|
ExtraConfig: []fstests.ExtraConfigItem{
|
|
|
|
{Name: name, Key: "type", Value: "union"},
|
|
|
|
{Name: name, Key: "upstreams", Value: upstreams},
|
|
|
|
{Name: name, Key: "action_policy", Value: "all"},
|
|
|
|
{Name: name, Key: "create_policy", Value: "all"},
|
|
|
|
{Name: name, Key: "search_policy", Value: "all"},
|
|
|
|
},
|
|
|
|
UnimplementableFsMethods: []string{"OpenWriterAt", "DuplicateFiles"},
|
|
|
|
UnimplementableObjectMethods: []string{"MimeType"},
|
|
|
|
})
|
|
|
|
}
|