mirror of
https://github.com/octoleo/restic.git
synced 2024-11-10 23:31:09 +00:00
f92ecf13c9
github.com/pkg/errors is no longer getting updates, because Go 1.13 went with the more flexible errors.{As,Is} function. Use those instead: errors from pkg/errors already support the Unwrap interface used by 1.13 error handling. Also: * check for io.EOF with a straight ==. That value should not be wrapped, and the chunker (whose error is checked in the cases changed) does not wrap it. * Give custom Error methods pointer receivers, so there's no ambiguity when type-switching since the value type will no longer implement error. * Make restic.ErrAlreadyLocked private, and rename it to alreadyLockedError to match the stdlib convention that error type names end in Error. * Same with rest.ErrIsNotExist => rest.notExistError. * Make s3.Backend.IsAccessDenied a private function.
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package rclone_test
|
|
|
|
import (
|
|
"context"
|
|
"os/exec"
|
|
"testing"
|
|
|
|
"github.com/restic/restic/internal/backend/rclone"
|
|
"github.com/restic/restic/internal/backend/test"
|
|
"github.com/restic/restic/internal/errors"
|
|
"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()
|
|
cfg.Remote = dir
|
|
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)
|
|
be, err := rclone.Create(context.TODO(), cfg)
|
|
var e *exec.Error
|
|
if errors.As(err, &e) && e.Err == exec.ErrNotFound {
|
|
t.Skipf("program %q not found", e.Name)
|
|
return nil, nil
|
|
}
|
|
return be, err
|
|
},
|
|
|
|
// 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)
|
|
return rclone.Open(cfg, nil)
|
|
},
|
|
|
|
// 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)
|
|
}
|