2018-03-13 21:30:51 +00:00
|
|
|
package rclone_test
|
|
|
|
|
|
|
|
import (
|
2018-03-14 20:14:54 +00:00
|
|
|
"os/exec"
|
2018-03-13 21:30:51 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/restic/restic/internal/backend/rclone"
|
|
|
|
"github.com/restic/restic/internal/backend/test"
|
|
|
|
rtest "github.com/restic/restic/internal/test"
|
|
|
|
)
|
|
|
|
|
2023-04-21 19:06:56 +00:00
|
|
|
func newTestSuite(t testing.TB) *test.Suite[rclone.Config] {
|
2022-12-09 12:42:33 +00:00
|
|
|
dir := rtest.TempDir(t)
|
2018-03-13 21:30:51 +00:00
|
|
|
|
2023-04-21 19:06:56 +00:00
|
|
|
return &test.Suite[rclone.Config]{
|
2018-03-13 21:30:51 +00:00
|
|
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
2023-04-21 19:35:34 +00:00
|
|
|
NewConfig: func() (*rclone.Config, error) {
|
2018-03-13 21:30:51 +00:00
|
|
|
t.Logf("use backend at %v", dir)
|
|
|
|
cfg := rclone.NewConfig()
|
2018-03-15 18:00:25 +00:00
|
|
|
cfg.Remote = dir
|
2023-04-21 19:35:34 +00:00
|
|
|
return &cfg, nil
|
2018-03-13 21:30:51 +00:00
|
|
|
},
|
|
|
|
|
2023-06-08 14:53:55 +00:00
|
|
|
Factory: rclone.NewFactory(),
|
|
|
|
}
|
|
|
|
}
|
2018-03-13 21:30:51 +00:00
|
|
|
|
2023-06-08 14:53:55 +00:00
|
|
|
func findRclone(t testing.TB) {
|
|
|
|
// try to find a rclone binary
|
|
|
|
_, err := exec.LookPath("rclone")
|
|
|
|
if err != nil {
|
|
|
|
t.Skip(err)
|
2018-03-13 21:30:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBackendRclone(t *testing.T) {
|
|
|
|
defer func() {
|
|
|
|
if t.Skipped() {
|
|
|
|
rtest.SkipDisallowed(t, "restic/backend/rclone.TestBackendRclone")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2023-06-08 14:53:55 +00:00
|
|
|
findRclone(t)
|
2018-03-13 21:30:51 +00:00
|
|
|
newTestSuite(t).RunTests(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkBackendREST(t *testing.B) {
|
2023-06-08 14:53:55 +00:00
|
|
|
findRclone(t)
|
2018-03-13 21:30:51 +00:00
|
|
|
newTestSuite(t).RunBenchmarks(t)
|
|
|
|
}
|