2018-03-13 21:30:51 +00:00
|
|
|
package rclone_test
|
|
|
|
|
|
|
|
import (
|
2020-04-10 10:08:52 +00:00
|
|
|
"context"
|
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"
|
2018-03-14 20:14:54 +00:00
|
|
|
"github.com/restic/restic/internal/errors"
|
2018-03-13 21:30:51 +00:00
|
|
|
"github.com/restic/restic/internal/restic"
|
|
|
|
rtest "github.com/restic/restic/internal/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newTestSuite(t testing.TB) *test.Suite {
|
|
|
|
dir, cleanup := rtest.TempDir(t)
|
|
|
|
|
|
|
|
return &test.Suite{
|
|
|
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
|
|
|
NewConfig: func() (interface{}, error) {
|
|
|
|
t.Logf("use backend at %v", dir)
|
|
|
|
cfg := rclone.NewConfig()
|
2018-03-15 18:00:25 +00:00
|
|
|
cfg.Remote = dir
|
2018-03-13 21:30:51 +00:00
|
|
|
return cfg, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
// CreateFn is a function that creates a temporary repository for the tests.
|
|
|
|
Create: func(config interface{}) (restic.Backend, error) {
|
|
|
|
t.Logf("Create()")
|
|
|
|
cfg := config.(rclone.Config)
|
2020-04-10 10:08:52 +00:00
|
|
|
be, err := rclone.Create(context.TODO(), cfg)
|
2022-06-13 18:35:37 +00:00
|
|
|
var e *exec.Error
|
|
|
|
if errors.As(err, &e) && e.Err == exec.ErrNotFound {
|
2018-03-14 20:14:54 +00:00
|
|
|
t.Skipf("program %q not found", e.Name)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return be, err
|
2018-03-13 21:30:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// OpenFn is a function that opens a previously created temporary repository.
|
|
|
|
Open: func(config interface{}) (restic.Backend, error) {
|
|
|
|
t.Logf("Open()")
|
|
|
|
cfg := config.(rclone.Config)
|
2018-05-22 18:48:17 +00:00
|
|
|
return rclone.Open(cfg, nil)
|
2018-03-13 21:30:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// CleanupFn removes data created during the tests.
|
|
|
|
Cleanup: func(config interface{}) error {
|
|
|
|
t.Logf("cleanup dir %v", dir)
|
|
|
|
cleanup()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBackendRclone(t *testing.T) {
|
|
|
|
defer func() {
|
|
|
|
if t.Skipped() {
|
|
|
|
rtest.SkipDisallowed(t, "restic/backend/rclone.TestBackendRclone")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
newTestSuite(t).RunTests(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkBackendREST(t *testing.B) {
|
|
|
|
newTestSuite(t).RunBenchmarks(t)
|
|
|
|
}
|