mirror of
https://github.com/restic/restic.git
synced 2025-10-09 19:20:23 +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,7 +1,6 @@
|
||||
package sftp_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -11,7 +10,6 @@ import (
|
||||
"github.com/restic/restic/internal/backend/sftp"
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -33,11 +31,7 @@ func newTestSuite(t testing.TB) *test.Suite[sftp.Config] {
|
||||
return &test.Suite[sftp.Config]{
|
||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||
NewConfig: func() (*sftp.Config, error) {
|
||||
dir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-sftp-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
dir := rtest.TempDir(t)
|
||||
t.Logf("create new backend at %v", dir)
|
||||
|
||||
cfg := &sftp.Config{
|
||||
@@ -48,25 +42,7 @@ func newTestSuite(t testing.TB) *test.Suite[sftp.Config] {
|
||||
return cfg, nil
|
||||
},
|
||||
|
||||
// CreateFn is a function that creates a temporary repository for the tests.
|
||||
Create: func(cfg sftp.Config) (restic.Backend, error) {
|
||||
return sftp.Create(context.TODO(), cfg)
|
||||
},
|
||||
|
||||
// OpenFn is a function that opens a previously created temporary repository.
|
||||
Open: func(cfg sftp.Config) (restic.Backend, error) {
|
||||
return sftp.Open(context.TODO(), cfg)
|
||||
},
|
||||
|
||||
// CleanupFn removes data created during the tests.
|
||||
Cleanup: func(cfg sftp.Config) error {
|
||||
if !rtest.TestCleanupTempDirs {
|
||||
t.Logf("leaving test backend dir at %v", cfg.Path)
|
||||
}
|
||||
|
||||
rtest.RemoveAll(t, cfg.Path)
|
||||
return nil
|
||||
},
|
||||
Factory: sftp.NewFactory(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user