backend: use generic instead of any type for test suite

This commit is contained in:
Michael Eischer 2023-04-21 21:06:56 +02:00
parent fa361dbfbd
commit a27b7f1370
13 changed files with 108 additions and 146 deletions

View file

@ -12,12 +12,12 @@ import (
rtest "github.com/restic/restic/internal/test"
)
func newTestSuite(t testing.TB) *test.Suite {
func newTestSuite(t testing.TB) *test.Suite[rclone.Config] {
dir := rtest.TempDir(t)
return &test.Suite{
return &test.Suite[rclone.Config]{
// NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (interface{}, error) {
NewConfig: func() (rclone.Config, error) {
t.Logf("use backend at %v", dir)
cfg := rclone.NewConfig()
cfg.Remote = dir
@ -25,9 +25,8 @@ func newTestSuite(t testing.TB) *test.Suite {
},
// CreateFn is a function that creates a temporary repository for the tests.
Create: func(config interface{}) (restic.Backend, error) {
Create: func(cfg rclone.Config) (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 {
@ -38,9 +37,8 @@ func newTestSuite(t testing.TB) *test.Suite {
},
// OpenFn is a function that opens a previously created temporary repository.
Open: func(config interface{}) (restic.Backend, error) {
Open: func(cfg rclone.Config) (restic.Backend, error) {
t.Logf("Open()")
cfg := config.(rclone.Config)
return rclone.Open(cfg, nil)
},
}