backend: Adjust tests to use the Factory to instantiate the backend
This drastically reduces the amount of duplicated test code.
This commit is contained in:
parent
3d3bb88745
commit
13a8b5822f
13 changed files with 119 additions and 423 deletions
|
@ -1,14 +1,11 @@
|
|||
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"
|
||||
)
|
||||
|
||||
|
@ -24,23 +21,15 @@ func newTestSuite(t testing.TB) *test.Suite[rclone.Config] {
|
|||
return &cfg, nil
|
||||
},
|
||||
|
||||
// CreateFn is a function that creates a temporary repository for the tests.
|
||||
Create: func(cfg rclone.Config) (restic.Backend, error) {
|
||||
t.Logf("Create()")
|
||||
be, err := rclone.Create(context.TODO(), cfg, nil)
|
||||
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
|
||||
},
|
||||
Factory: rclone.NewFactory(),
|
||||
}
|
||||
}
|
||||
|
||||
// OpenFn is a function that opens a previously created temporary repository.
|
||||
Open: func(cfg rclone.Config) (restic.Backend, error) {
|
||||
t.Logf("Open()")
|
||||
return rclone.Open(context.TODO(), cfg, nil)
|
||||
},
|
||||
func findRclone(t testing.TB) {
|
||||
// try to find a rclone binary
|
||||
_, err := exec.LookPath("rclone")
|
||||
if err != nil {
|
||||
t.Skip(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,9 +40,11 @@ func TestBackendRclone(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
findRclone(t)
|
||||
newTestSuite(t).RunTests(t)
|
||||
}
|
||||
|
||||
func BenchmarkBackendREST(t *testing.B) {
|
||||
findRclone(t)
|
||||
newTestSuite(t).RunBenchmarks(t)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue