mirror of
https://github.com/restic/restic.git
synced 2025-08-11 12:07:46 +00:00
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:
@@ -1,26 +1,18 @@
|
||||
package b2_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/backend/b2"
|
||||
"github.com/restic/restic/internal/backend/test"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func newB2TestSuite(t testing.TB) *test.Suite[b2.Config] {
|
||||
tr, err := backend.Transport(backend.TransportOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("cannot create transport for tests: %v", err)
|
||||
}
|
||||
|
||||
return &test.Suite[b2.Config]{
|
||||
// do not use excessive data
|
||||
MinimalData: true,
|
||||
@@ -40,25 +32,7 @@ func newB2TestSuite(t testing.TB) *test.Suite[b2.Config] {
|
||||
return cfg, nil
|
||||
},
|
||||
|
||||
// CreateFn is a function that creates a temporary repository for the tests.
|
||||
Create: func(cfg b2.Config) (restic.Backend, error) {
|
||||
return b2.Create(context.Background(), cfg, tr)
|
||||
},
|
||||
|
||||
// OpenFn is a function that opens a previously created temporary repository.
|
||||
Open: func(cfg b2.Config) (restic.Backend, error) {
|
||||
return b2.Open(context.Background(), cfg, tr)
|
||||
},
|
||||
|
||||
// CleanupFn removes data created during the tests.
|
||||
Cleanup: func(cfg b2.Config) error {
|
||||
be, err := b2.Open(context.Background(), cfg, tr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return be.Delete(context.TODO())
|
||||
},
|
||||
Factory: b2.NewFactory(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user