"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
testserver: start the test server for remotes wrapped by chunker, crypt etc
Nick Craig-Wood918f5a68eedd
diff --git a/fstest/test_all/test_all.go b/fstest/test_all/test_all.goindex 14f183f80..e5e15181b 100644--- a/fstest/test_all/test_all.go+++ b/fstest/test_all/test_all.go@@ -22,6 +22,7 @@ import (_ "github.com/rclone/rclone/backend/all" // import all fs"github.com/rclone/rclone/fs"+ "github.com/rclone/rclone/fs/config""github.com/rclone/rclone/fs/config/configfile""github.com/rclone/rclone/fstest/runs""github.com/rclone/rclone/fstest/testserver"@@ -66,6 +67,10 @@ func main() {fs.Log(nil, "test_all should be run from the root of the rclone source code")fs.Fatal(nil, fmt.Sprint(err))}+ // Use the same config file as the tests, so test servers for wrapped remotes are found+ if envConfig := os.Getenv("RCLONE_CONFIG"); envConfig != "" {+ _ = config.SetConfigPath(envConfig)+ }configfile.Install()// Seed the random number generatordiff --git a/fstest/testserver/testserver.go b/fstest/testserver/testserver.goindex 687078fe6..e6b44733e 100644--- a/fstest/testserver/testserver.go+++ b/fstest/testserver/testserver.go@@ -15,6 +15,7 @@ import ("time""github.com/rclone/rclone/fs"+ "github.com/rclone/rclone/fs/config""github.com/rclone/rclone/fs/fspath")@@ -160,10 +161,21 @@ func stop(name string) {func stopNothing() {}+// maxWrapDepth limits how many wrapping remotes Start follows+const maxWrapDepth = 10+// Start starts the test server for remoteName.//+// If remoteName has no start command but wraps another remote (via+// its "remote" config value), such as chunker or crypt, the server+// for the wrapped remote is started instead.+//// This must be stopped by calling the function returned when finished.func Start(remote string) (fn func(), err error) {+ return startRemote(remote, 0)+}++func startRemote(remote string, depth int) (fn func(), err error) {// don't start the local backendif remote == "" {return stopNothing, nil@@ -186,8 +198,11 @@ func Start(remote string) (fn func(), err error) {return nil, err}- // If remote has no start command then do nothing+ // If remote has no start command then start the remote it wraps, if anyif !hasStartCommand(name) {+ if wrapped := config.GetValue(name, "remote"); wrapped != "" && depth < maxWrapDepth {+ return startRemote(wrapped, depth+1)+ }return stopNothing, nil}diff --git a/fstest/testserver/testserver_test.go b/fstest/testserver/testserver_test.gonew file mode 100644index 000000000..18e9517c5--- /dev/null+++ b/fstest/testserver/testserver_test.go@@ -0,0 +1,61 @@+package testserver++import (+ "os"+ "path/filepath"+ "runtime"+ "testing"++ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"+)++// setupFakeServer points the testserver at a temporary init.d holding+// a TestFake server script which records when it is stopped.+func setupFakeServer(t *testing.T) (stopped string) {+ if runtime.GOOS == "windows" {+ t.Skip("init.d scripts need a POSIX shell")+ }+ dir := t.TempDir()+ stopped = filepath.Join(dir, "stopped")+ script := `#!/bin/sh+case "$1" in+start) echo type=memory ;;+stop) touch "` + stopped + `" ;;+esac+`+ require.NoError(t, os.WriteFile(filepath.Join(dir, "TestFake"), []byte(script), 0o755))+ findConfigOnce.Do(func() {})+ oldConfigDir := configDir+ configDir = dir+ t.Cleanup(func() { configDir = oldConfigDir })+ return stopped+}++func TestStartWrapped(t *testing.T) {+ stopped := setupFakeServer(t)+ t.Setenv("RCLONE_CONFIG_TESTFAKE_TYPE", "")+ t.Setenv("RCLONE_CONFIG_TESTWRAP_TYPE", "chunker")+ t.Setenv("RCLONE_CONFIG_TESTWRAP_REMOTE", "TestFake:")+ t.Setenv("RCLONE_CONFIG_TESTWRAPWRAP_TYPE", "crypt")+ t.Setenv("RCLONE_CONFIG_TESTWRAPWRAP_REMOTE", "TestWrap:sub/dir")++ finish, err := Start("TestWrapWrap:")+ require.NoError(t, err)+ assert.Equal(t, "memory", os.Getenv("RCLONE_CONFIG_TESTFAKE_TYPE"))+ assert.NoFileExists(t, stopped)++ finish()+ assert.FileExists(t, stopped)+}++func TestStartWrappedLoop(t *testing.T) {+ stopped := setupFakeServer(t)+ t.Setenv("RCLONE_CONFIG_TESTLOOP_TYPE", "chunker")+ t.Setenv("RCLONE_CONFIG_TESTLOOP_REMOTE", "TestLoop:")++ finish, err := Start("TestLoop:")+ require.NoError(t, err)+ finish()+ assert.NoFileExists(t, stopped)+}