forked from TrueCloudLab/restic
backend: use generic instead of any type for test suite
This commit is contained in:
parent
fa361dbfbd
commit
a27b7f1370
13 changed files with 108 additions and 146 deletions
|
@ -18,21 +18,21 @@ import (
|
||||||
rtest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newAzureTestSuite(t testing.TB) *test.Suite {
|
func newAzureTestSuite(t testing.TB) *test.Suite[azure.Config] {
|
||||||
tr, err := backend.Transport(backend.TransportOptions{})
|
tr, err := backend.Transport(backend.TransportOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot create transport for tests: %v", err)
|
t.Fatalf("cannot create transport for tests: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &test.Suite{
|
return &test.Suite[azure.Config]{
|
||||||
// do not use excessive data
|
// do not use excessive data
|
||||||
MinimalData: true,
|
MinimalData: true,
|
||||||
|
|
||||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||||
NewConfig: func() (interface{}, error) {
|
NewConfig: func() (azure.Config, error) {
|
||||||
cfg, err := azure.ParseConfig(os.Getenv("RESTIC_TEST_AZURE_REPOSITORY"))
|
cfg, err := azure.ParseConfig(os.Getenv("RESTIC_TEST_AZURE_REPOSITORY"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return azure.Config{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.AccountName = os.Getenv("RESTIC_TEST_AZURE_ACCOUNT_NAME")
|
cfg.AccountName = os.Getenv("RESTIC_TEST_AZURE_ACCOUNT_NAME")
|
||||||
|
@ -42,9 +42,7 @@ func newAzureTestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// CreateFn is a function that creates a temporary repository for the tests.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create: func(config interface{}) (restic.Backend, error) {
|
Create: func(cfg azure.Config) (restic.Backend, error) {
|
||||||
cfg := config.(azure.Config)
|
|
||||||
|
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
be, err := azure.Create(ctx, cfg, tr)
|
be, err := azure.Create(ctx, cfg, tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -64,15 +62,13 @@ func newAzureTestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// OpenFn is a function that opens a previously created temporary repository.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
Open: func(config interface{}) (restic.Backend, error) {
|
Open: func(cfg azure.Config) (restic.Backend, error) {
|
||||||
cfg := config.(azure.Config)
|
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
return azure.Open(ctx, cfg, tr)
|
return azure.Open(ctx, cfg, tr)
|
||||||
},
|
},
|
||||||
|
|
||||||
// CleanupFn removes data created during the tests.
|
// CleanupFn removes data created during the tests.
|
||||||
Cleanup: func(config interface{}) error {
|
Cleanup: func(cfg azure.Config) error {
|
||||||
cfg := config.(azure.Config)
|
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
be, err := azure.Open(ctx, cfg, tr)
|
be, err := azure.Open(ctx, cfg, tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -16,13 +16,13 @@ import (
|
||||||
rtest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newB2TestSuite(t testing.TB) *test.Suite {
|
func newB2TestSuite(t testing.TB) *test.Suite[b2.Config] {
|
||||||
tr, err := backend.Transport(backend.TransportOptions{})
|
tr, err := backend.Transport(backend.TransportOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot create transport for tests: %v", err)
|
t.Fatalf("cannot create transport for tests: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &test.Suite{
|
return &test.Suite[b2.Config]{
|
||||||
// do not use excessive data
|
// do not use excessive data
|
||||||
MinimalData: true,
|
MinimalData: true,
|
||||||
|
|
||||||
|
@ -30,10 +30,10 @@ func newB2TestSuite(t testing.TB) *test.Suite {
|
||||||
WaitForDelayedRemoval: 10 * time.Second,
|
WaitForDelayedRemoval: 10 * time.Second,
|
||||||
|
|
||||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||||
NewConfig: func() (interface{}, error) {
|
NewConfig: func() (b2.Config, error) {
|
||||||
cfg, err := b2.ParseConfig(os.Getenv("RESTIC_TEST_B2_REPOSITORY"))
|
cfg, err := b2.ParseConfig(os.Getenv("RESTIC_TEST_B2_REPOSITORY"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return b2.Config{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.AccountID = os.Getenv("RESTIC_TEST_B2_ACCOUNT_ID")
|
cfg.AccountID = os.Getenv("RESTIC_TEST_B2_ACCOUNT_ID")
|
||||||
|
@ -43,20 +43,17 @@ func newB2TestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// CreateFn is a function that creates a temporary repository for the tests.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create: func(config interface{}) (restic.Backend, error) {
|
Create: func(cfg b2.Config) (restic.Backend, error) {
|
||||||
cfg := config.(b2.Config)
|
|
||||||
return b2.Create(context.Background(), cfg, tr)
|
return b2.Create(context.Background(), cfg, tr)
|
||||||
},
|
},
|
||||||
|
|
||||||
// OpenFn is a function that opens a previously created temporary repository.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
Open: func(config interface{}) (restic.Backend, error) {
|
Open: func(cfg b2.Config) (restic.Backend, error) {
|
||||||
cfg := config.(b2.Config)
|
|
||||||
return b2.Open(context.Background(), cfg, tr)
|
return b2.Open(context.Background(), cfg, tr)
|
||||||
},
|
},
|
||||||
|
|
||||||
// CleanupFn removes data created during the tests.
|
// CleanupFn removes data created during the tests.
|
||||||
Cleanup: func(config interface{}) error {
|
Cleanup: func(cfg b2.Config) error {
|
||||||
cfg := config.(b2.Config)
|
|
||||||
be, err := b2.Open(context.Background(), cfg, tr)
|
be, err := b2.Open(context.Background(), cfg, tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -15,21 +15,21 @@ import (
|
||||||
rtest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newGSTestSuite(t testing.TB) *test.Suite {
|
func newGSTestSuite(t testing.TB) *test.Suite[gs.Config] {
|
||||||
tr, err := backend.Transport(backend.TransportOptions{})
|
tr, err := backend.Transport(backend.TransportOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot create transport for tests: %v", err)
|
t.Fatalf("cannot create transport for tests: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &test.Suite{
|
return &test.Suite[gs.Config]{
|
||||||
// do not use excessive data
|
// do not use excessive data
|
||||||
MinimalData: true,
|
MinimalData: true,
|
||||||
|
|
||||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||||
NewConfig: func() (interface{}, error) {
|
NewConfig: func() (gs.Config, error) {
|
||||||
cfg, err := gs.ParseConfig(os.Getenv("RESTIC_TEST_GS_REPOSITORY"))
|
cfg, err := gs.ParseConfig(os.Getenv("RESTIC_TEST_GS_REPOSITORY"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return gs.Config{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.ProjectID = os.Getenv("RESTIC_TEST_GS_PROJECT_ID")
|
cfg.ProjectID = os.Getenv("RESTIC_TEST_GS_PROJECT_ID")
|
||||||
|
@ -38,9 +38,7 @@ func newGSTestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// CreateFn is a function that creates a temporary repository for the tests.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create: func(config interface{}) (restic.Backend, error) {
|
Create: func(cfg gs.Config) (restic.Backend, error) {
|
||||||
cfg := config.(gs.Config)
|
|
||||||
|
|
||||||
be, err := gs.Create(context.Background(), cfg, tr)
|
be, err := gs.Create(context.Background(), cfg, tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -59,15 +57,12 @@ func newGSTestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// OpenFn is a function that opens a previously created temporary repository.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
Open: func(config interface{}) (restic.Backend, error) {
|
Open: func(cfg gs.Config) (restic.Backend, error) {
|
||||||
cfg := config.(gs.Config)
|
|
||||||
return gs.Open(cfg, tr)
|
return gs.Open(cfg, tr)
|
||||||
},
|
},
|
||||||
|
|
||||||
// CleanupFn removes data created during the tests.
|
// CleanupFn removes data created during the tests.
|
||||||
Cleanup: func(config interface{}) error {
|
Cleanup: func(cfg gs.Config) error {
|
||||||
cfg := config.(gs.Config)
|
|
||||||
|
|
||||||
be, err := gs.Open(cfg, tr)
|
be, err := gs.Open(cfg, tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -12,10 +12,10 @@ import (
|
||||||
rtest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestSuite(t testing.TB) *test.Suite {
|
func newTestSuite(t testing.TB) *test.Suite[local.Config] {
|
||||||
return &test.Suite{
|
return &test.Suite[local.Config]{
|
||||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||||
NewConfig: func() (interface{}, error) {
|
NewConfig: func() (local.Config, error) {
|
||||||
dir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-local-")
|
dir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-local-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -31,20 +31,17 @@ func newTestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// CreateFn is a function that creates a temporary repository for the tests.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create: func(config interface{}) (restic.Backend, error) {
|
Create: func(cfg local.Config) (restic.Backend, error) {
|
||||||
cfg := config.(local.Config)
|
|
||||||
return local.Create(context.TODO(), cfg)
|
return local.Create(context.TODO(), cfg)
|
||||||
},
|
},
|
||||||
|
|
||||||
// OpenFn is a function that opens a previously created temporary repository.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
Open: func(config interface{}) (restic.Backend, error) {
|
Open: func(cfg local.Config) (restic.Backend, error) {
|
||||||
cfg := config.(local.Config)
|
|
||||||
return local.Open(context.TODO(), cfg)
|
return local.Open(context.TODO(), cfg)
|
||||||
},
|
},
|
||||||
|
|
||||||
// CleanupFn removes data created during the tests.
|
// CleanupFn removes data created during the tests.
|
||||||
Cleanup: func(config interface{}) error {
|
Cleanup: func(cfg local.Config) error {
|
||||||
cfg := config.(local.Config)
|
|
||||||
if !rtest.TestCleanupTempDirs {
|
if !rtest.TestCleanupTempDirs {
|
||||||
t.Logf("leaving test backend dir at %v", cfg.Path)
|
t.Logf("leaving test backend dir at %v", cfg.Path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,19 +15,18 @@ type memConfig struct {
|
||||||
be restic.Backend
|
be restic.Backend
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestSuite() *test.Suite {
|
func newTestSuite() *test.Suite[*memConfig] {
|
||||||
return &test.Suite{
|
return &test.Suite[*memConfig]{
|
||||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||||
NewConfig: func() (interface{}, error) {
|
NewConfig: func() (*memConfig, error) {
|
||||||
return &memConfig{}, nil
|
return &memConfig{}, nil
|
||||||
},
|
},
|
||||||
|
|
||||||
// CreateFn is a function that creates a temporary repository for the tests.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create: func(cfg interface{}) (restic.Backend, error) {
|
Create: func(cfg *memConfig) (restic.Backend, error) {
|
||||||
c := cfg.(*memConfig)
|
if cfg.be != nil {
|
||||||
if c.be != nil {
|
_, err := cfg.be.Stat(context.TODO(), restic.Handle{Type: restic.ConfigFile})
|
||||||
_, err := c.be.Stat(context.TODO(), restic.Handle{Type: restic.ConfigFile})
|
if err != nil && !cfg.be.IsNotExist(err) {
|
||||||
if err != nil && !c.be.IsNotExist(err) {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,21 +35,20 @@ func newTestSuite() *test.Suite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.be = mem.New()
|
cfg.be = mem.New()
|
||||||
return c.be, nil
|
return cfg.be, nil
|
||||||
},
|
},
|
||||||
|
|
||||||
// OpenFn is a function that opens a previously created temporary repository.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
Open: func(cfg interface{}) (restic.Backend, error) {
|
Open: func(cfg *memConfig) (restic.Backend, error) {
|
||||||
c := cfg.(*memConfig)
|
if cfg.be == nil {
|
||||||
if c.be == nil {
|
cfg.be = mem.New()
|
||||||
c.be = mem.New()
|
|
||||||
}
|
}
|
||||||
return c.be, nil
|
return cfg.be, nil
|
||||||
},
|
},
|
||||||
|
|
||||||
// CleanupFn removes data created during the tests.
|
// CleanupFn removes data created during the tests.
|
||||||
Cleanup: func(cfg interface{}) error {
|
Cleanup: func(cfg *memConfig) error {
|
||||||
// no cleanup needed
|
// no cleanup needed
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,12 +12,12 @@ import (
|
||||||
rtest "github.com/restic/restic/internal/test"
|
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)
|
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 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)
|
t.Logf("use backend at %v", dir)
|
||||||
cfg := rclone.NewConfig()
|
cfg := rclone.NewConfig()
|
||||||
cfg.Remote = dir
|
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.
|
// 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()")
|
t.Logf("Create()")
|
||||||
cfg := config.(rclone.Config)
|
|
||||||
be, err := rclone.Create(context.TODO(), cfg)
|
be, err := rclone.Create(context.TODO(), cfg)
|
||||||
var e *exec.Error
|
var e *exec.Error
|
||||||
if errors.As(err, &e) && e.Err == exec.ErrNotFound {
|
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.
|
// 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()")
|
t.Logf("Open()")
|
||||||
cfg := config.(rclone.Config)
|
|
||||||
return rclone.Open(cfg, nil)
|
return rclone.Open(cfg, nil)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,36 +67,34 @@ func runRESTServer(ctx context.Context, t testing.TB, dir string) (*url.URL, fun
|
||||||
return url, cleanup
|
return url, cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestSuite(_ context.Context, t testing.TB, url *url.URL, minimalData bool) *test.Suite {
|
func newTestSuite(_ context.Context, t testing.TB, url *url.URL, minimalData bool) *test.Suite[rest.Config] {
|
||||||
tr, err := backend.Transport(backend.TransportOptions{})
|
tr, err := backend.Transport(backend.TransportOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot create transport for tests: %v", err)
|
t.Fatalf("cannot create transport for tests: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &test.Suite{
|
return &test.Suite[rest.Config]{
|
||||||
MinimalData: minimalData,
|
MinimalData: minimalData,
|
||||||
|
|
||||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||||
NewConfig: func() (interface{}, error) {
|
NewConfig: func() (rest.Config, error) {
|
||||||
cfg := rest.NewConfig()
|
cfg := rest.NewConfig()
|
||||||
cfg.URL = url
|
cfg.URL = url
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
},
|
},
|
||||||
|
|
||||||
// CreateFn is a function that creates a temporary repository for the tests.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create: func(config interface{}) (restic.Backend, error) {
|
Create: func(cfg rest.Config) (restic.Backend, error) {
|
||||||
cfg := config.(rest.Config)
|
|
||||||
return rest.Create(context.TODO(), cfg, tr)
|
return rest.Create(context.TODO(), cfg, tr)
|
||||||
},
|
},
|
||||||
|
|
||||||
// OpenFn is a function that opens a previously created temporary repository.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
Open: func(config interface{}) (restic.Backend, error) {
|
Open: func(cfg rest.Config) (restic.Backend, error) {
|
||||||
cfg := config.(rest.Config)
|
|
||||||
return rest.Open(cfg, tr)
|
return rest.Open(cfg, tr)
|
||||||
},
|
},
|
||||||
|
|
||||||
// CleanupFn removes data created during the tests.
|
// CleanupFn removes data created during the tests.
|
||||||
Cleanup: func(config interface{}) error {
|
Cleanup: func(cfg rest.Config) error {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,15 +120,15 @@ func createS3(t testing.TB, cfg MinioTestConfig, tr http.RoundTripper) (be resti
|
||||||
return be, err
|
return be, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMinioTestSuite(ctx context.Context, t testing.TB) *test.Suite {
|
func newMinioTestSuite(ctx context.Context, t testing.TB) *test.Suite[MinioTestConfig] {
|
||||||
tr, err := backend.Transport(backend.TransportOptions{})
|
tr, err := backend.Transport(backend.TransportOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot create transport for tests: %v", err)
|
t.Fatalf("cannot create transport for tests: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &test.Suite{
|
return &test.Suite[MinioTestConfig]{
|
||||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||||
NewConfig: func() (interface{}, error) {
|
NewConfig: func() (MinioTestConfig, error) {
|
||||||
cfg := MinioTestConfig{}
|
cfg := MinioTestConfig{}
|
||||||
|
|
||||||
cfg.tempdir = rtest.TempDir(t)
|
cfg.tempdir = rtest.TempDir(t)
|
||||||
|
@ -146,9 +146,7 @@ func newMinioTestSuite(ctx context.Context, t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// CreateFn is a function that creates a temporary repository for the tests.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create: func(config interface{}) (restic.Backend, error) {
|
Create: func(cfg MinioTestConfig) (restic.Backend, error) {
|
||||||
cfg := config.(MinioTestConfig)
|
|
||||||
|
|
||||||
be, err := createS3(t, cfg, tr)
|
be, err := createS3(t, cfg, tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -167,14 +165,12 @@ func newMinioTestSuite(ctx context.Context, t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// OpenFn is a function that opens a previously created temporary repository.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
Open: func(config interface{}) (restic.Backend, error) {
|
Open: func(cfg MinioTestConfig) (restic.Backend, error) {
|
||||||
cfg := config.(MinioTestConfig)
|
|
||||||
return s3.Open(ctx, cfg.Config, tr)
|
return s3.Open(ctx, cfg.Config, tr)
|
||||||
},
|
},
|
||||||
|
|
||||||
// CleanupFn removes data created during the tests.
|
// CleanupFn removes data created during the tests.
|
||||||
Cleanup: func(config interface{}) error {
|
Cleanup: func(cfg MinioTestConfig) error {
|
||||||
cfg := config.(MinioTestConfig)
|
|
||||||
if cfg.stopServer != nil {
|
if cfg.stopServer != nil {
|
||||||
cfg.stopServer()
|
cfg.stopServer()
|
||||||
}
|
}
|
||||||
|
@ -217,21 +213,21 @@ func BenchmarkBackendMinio(t *testing.B) {
|
||||||
newMinioTestSuite(ctx, t).RunBenchmarks(t)
|
newMinioTestSuite(ctx, t).RunBenchmarks(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newS3TestSuite(t testing.TB) *test.Suite {
|
func newS3TestSuite(t testing.TB) *test.Suite[s3.Config] {
|
||||||
tr, err := backend.Transport(backend.TransportOptions{})
|
tr, err := backend.Transport(backend.TransportOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot create transport for tests: %v", err)
|
t.Fatalf("cannot create transport for tests: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &test.Suite{
|
return &test.Suite[s3.Config]{
|
||||||
// do not use excessive data
|
// do not use excessive data
|
||||||
MinimalData: true,
|
MinimalData: true,
|
||||||
|
|
||||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||||
NewConfig: func() (interface{}, error) {
|
NewConfig: func() (s3.Config, error) {
|
||||||
cfg, err := s3.ParseConfig(os.Getenv("RESTIC_TEST_S3_REPOSITORY"))
|
cfg, err := s3.ParseConfig(os.Getenv("RESTIC_TEST_S3_REPOSITORY"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return s3.Config{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.KeyID = os.Getenv("RESTIC_TEST_S3_KEY")
|
cfg.KeyID = os.Getenv("RESTIC_TEST_S3_KEY")
|
||||||
|
@ -241,9 +237,7 @@ func newS3TestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// CreateFn is a function that creates a temporary repository for the tests.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create: func(config interface{}) (restic.Backend, error) {
|
Create: func(cfg s3.Config) (restic.Backend, error) {
|
||||||
cfg := config.(s3.Config)
|
|
||||||
|
|
||||||
be, err := s3.Create(context.TODO(), cfg, tr)
|
be, err := s3.Create(context.TODO(), cfg, tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -262,15 +256,12 @@ func newS3TestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// OpenFn is a function that opens a previously created temporary repository.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
Open: func(config interface{}) (restic.Backend, error) {
|
Open: func(cfg s3.Config) (restic.Backend, error) {
|
||||||
cfg := config.(s3.Config)
|
|
||||||
return s3.Open(context.TODO(), cfg, tr)
|
return s3.Open(context.TODO(), cfg, tr)
|
||||||
},
|
},
|
||||||
|
|
||||||
// CleanupFn removes data created during the tests.
|
// CleanupFn removes data created during the tests.
|
||||||
Cleanup: func(config interface{}) error {
|
Cleanup: func(cfg s3.Config) error {
|
||||||
cfg := config.(s3.Config)
|
|
||||||
|
|
||||||
be, err := s3.Open(context.TODO(), cfg, tr)
|
be, err := s3.Open(context.TODO(), cfg, tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -29,10 +29,10 @@ func findSFTPServerBinary() string {
|
||||||
|
|
||||||
var sftpServer = findSFTPServerBinary()
|
var sftpServer = findSFTPServerBinary()
|
||||||
|
|
||||||
func newTestSuite(t testing.TB) *test.Suite {
|
func newTestSuite(t testing.TB) *test.Suite[sftp.Config] {
|
||||||
return &test.Suite{
|
return &test.Suite[sftp.Config]{
|
||||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||||
NewConfig: func() (interface{}, error) {
|
NewConfig: func() (sftp.Config, error) {
|
||||||
dir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-sftp-")
|
dir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-sftp-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -49,20 +49,17 @@ func newTestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// CreateFn is a function that creates a temporary repository for the tests.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create: func(config interface{}) (restic.Backend, error) {
|
Create: func(cfg sftp.Config) (restic.Backend, error) {
|
||||||
cfg := config.(sftp.Config)
|
|
||||||
return sftp.Create(context.TODO(), cfg)
|
return sftp.Create(context.TODO(), cfg)
|
||||||
},
|
},
|
||||||
|
|
||||||
// OpenFn is a function that opens a previously created temporary repository.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
Open: func(config interface{}) (restic.Backend, error) {
|
Open: func(cfg sftp.Config) (restic.Backend, error) {
|
||||||
cfg := config.(sftp.Config)
|
|
||||||
return sftp.Open(context.TODO(), cfg)
|
return sftp.Open(context.TODO(), cfg)
|
||||||
},
|
},
|
||||||
|
|
||||||
// CleanupFn removes data created during the tests.
|
// CleanupFn removes data created during the tests.
|
||||||
Cleanup: func(config interface{}) error {
|
Cleanup: func(cfg sftp.Config) error {
|
||||||
cfg := config.(sftp.Config)
|
|
||||||
if !rtest.TestCleanupTempDirs {
|
if !rtest.TestCleanupTempDirs {
|
||||||
t.Logf("leaving test backend dir at %v", cfg.Path)
|
t.Logf("leaving test backend dir at %v", cfg.Path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,13 @@ import (
|
||||||
rtest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newSwiftTestSuite(t testing.TB) *test.Suite {
|
func newSwiftTestSuite(t testing.TB) *test.Suite[swift.Config] {
|
||||||
tr, err := backend.Transport(backend.TransportOptions{})
|
tr, err := backend.Transport(backend.TransportOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot create transport for tests: %v", err)
|
t.Fatalf("cannot create transport for tests: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &test.Suite{
|
return &test.Suite[swift.Config]{
|
||||||
// do not use excessive data
|
// do not use excessive data
|
||||||
MinimalData: true,
|
MinimalData: true,
|
||||||
|
|
||||||
|
@ -42,14 +42,14 @@ func newSwiftTestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||||
NewConfig: func() (interface{}, error) {
|
NewConfig: func() (swift.Config, error) {
|
||||||
cfg, err := swift.ParseConfig(os.Getenv("RESTIC_TEST_SWIFT"))
|
cfg, err := swift.ParseConfig(os.Getenv("RESTIC_TEST_SWIFT"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return swift.Config{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = swift.ApplyEnvironment("RESTIC_TEST_", &cfg); err != nil {
|
if err = swift.ApplyEnvironment("RESTIC_TEST_", &cfg); err != nil {
|
||||||
return nil, err
|
return swift.Config{}, err
|
||||||
}
|
}
|
||||||
cfg.Prefix += fmt.Sprintf("/test-%d", time.Now().UnixNano())
|
cfg.Prefix += fmt.Sprintf("/test-%d", time.Now().UnixNano())
|
||||||
t.Logf("using prefix %v", cfg.Prefix)
|
t.Logf("using prefix %v", cfg.Prefix)
|
||||||
|
@ -57,9 +57,7 @@ func newSwiftTestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// CreateFn is a function that creates a temporary repository for the tests.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create: func(config interface{}) (restic.Backend, error) {
|
Create: func(cfg swift.Config) (restic.Backend, error) {
|
||||||
cfg := config.(swift.Config)
|
|
||||||
|
|
||||||
be, err := swift.Open(context.TODO(), cfg, tr)
|
be, err := swift.Open(context.TODO(), cfg, tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -78,15 +76,12 @@ func newSwiftTestSuite(t testing.TB) *test.Suite {
|
||||||
},
|
},
|
||||||
|
|
||||||
// OpenFn is a function that opens a previously created temporary repository.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
Open: func(config interface{}) (restic.Backend, error) {
|
Open: func(cfg swift.Config) (restic.Backend, error) {
|
||||||
cfg := config.(swift.Config)
|
|
||||||
return swift.Open(context.TODO(), cfg, tr)
|
return swift.Open(context.TODO(), cfg, tr)
|
||||||
},
|
},
|
||||||
|
|
||||||
// CleanupFn removes data created during the tests.
|
// CleanupFn removes data created during the tests.
|
||||||
Cleanup: func(config interface{}) error {
|
Cleanup: func(cfg swift.Config) error {
|
||||||
cfg := config.(swift.Config)
|
|
||||||
|
|
||||||
be, err := swift.Open(context.TODO(), cfg, tr)
|
be, err := swift.Open(context.TODO(), cfg, tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -29,7 +29,7 @@ func remove(t testing.TB, be restic.Backend, h restic.Handle) {
|
||||||
|
|
||||||
// BenchmarkLoadFile benchmarks the Load() method of a backend by
|
// BenchmarkLoadFile benchmarks the Load() method of a backend by
|
||||||
// loading a complete file.
|
// loading a complete file.
|
||||||
func (s *Suite) BenchmarkLoadFile(t *testing.B) {
|
func (s *Suite[C]) BenchmarkLoadFile(t *testing.B) {
|
||||||
be := s.open(t)
|
be := s.open(t)
|
||||||
defer s.close(t, be)
|
defer s.close(t, be)
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ func (s *Suite) BenchmarkLoadFile(t *testing.B) {
|
||||||
|
|
||||||
// BenchmarkLoadPartialFile benchmarks the Load() method of a backend by
|
// BenchmarkLoadPartialFile benchmarks the Load() method of a backend by
|
||||||
// loading the remainder of a file starting at a given offset.
|
// loading the remainder of a file starting at a given offset.
|
||||||
func (s *Suite) BenchmarkLoadPartialFile(t *testing.B) {
|
func (s *Suite[C]) BenchmarkLoadPartialFile(t *testing.B) {
|
||||||
be := s.open(t)
|
be := s.open(t)
|
||||||
defer s.close(t, be)
|
defer s.close(t, be)
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ func (s *Suite) BenchmarkLoadPartialFile(t *testing.B) {
|
||||||
|
|
||||||
// BenchmarkLoadPartialFileOffset benchmarks the Load() method of a
|
// BenchmarkLoadPartialFileOffset benchmarks the Load() method of a
|
||||||
// backend by loading a number of bytes of a file starting at a given offset.
|
// backend by loading a number of bytes of a file starting at a given offset.
|
||||||
func (s *Suite) BenchmarkLoadPartialFileOffset(t *testing.B) {
|
func (s *Suite[C]) BenchmarkLoadPartialFileOffset(t *testing.B) {
|
||||||
be := s.open(t)
|
be := s.open(t)
|
||||||
defer s.close(t, be)
|
defer s.close(t, be)
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ func (s *Suite) BenchmarkLoadPartialFileOffset(t *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BenchmarkSave benchmarks the Save() method of a backend.
|
// BenchmarkSave benchmarks the Save() method of a backend.
|
||||||
func (s *Suite) BenchmarkSave(t *testing.B) {
|
func (s *Suite[C]) BenchmarkSave(t *testing.B) {
|
||||||
be := s.open(t)
|
be := s.open(t)
|
||||||
defer s.close(t, be)
|
defer s.close(t, be)
|
||||||
|
|
||||||
|
|
|
@ -11,21 +11,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Suite implements a test suite for restic backends.
|
// Suite implements a test suite for restic backends.
|
||||||
type Suite struct {
|
type Suite[C any] struct {
|
||||||
// Config should be used to configure the backend.
|
// Config should be used to configure the backend.
|
||||||
Config interface{}
|
Config C
|
||||||
|
|
||||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||||
NewConfig func() (interface{}, error)
|
NewConfig func() (C, error)
|
||||||
|
|
||||||
// CreateFn is a function that creates a temporary repository for the tests.
|
// CreateFn is a function that creates a temporary repository for the tests.
|
||||||
Create func(cfg interface{}) (restic.Backend, error)
|
Create func(cfg C) (restic.Backend, error)
|
||||||
|
|
||||||
// OpenFn is a function that opens a previously created temporary repository.
|
// OpenFn is a function that opens a previously created temporary repository.
|
||||||
Open func(cfg interface{}) (restic.Backend, error)
|
Open func(cfg C) (restic.Backend, error)
|
||||||
|
|
||||||
// CleanupFn removes data created during the tests.
|
// CleanupFn removes data created during the tests.
|
||||||
Cleanup func(cfg interface{}) error
|
Cleanup func(cfg C) error
|
||||||
|
|
||||||
// MinimalData instructs the tests to not use excessive data.
|
// MinimalData instructs the tests to not use excessive data.
|
||||||
MinimalData bool
|
MinimalData bool
|
||||||
|
@ -40,7 +40,7 @@ type Suite struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunTests executes all defined tests as subtests of t.
|
// RunTests executes all defined tests as subtests of t.
|
||||||
func (s *Suite) RunTests(t *testing.T) {
|
func (s *Suite[C]) RunTests(t *testing.T) {
|
||||||
var err error
|
var err error
|
||||||
s.Config, err = s.NewConfig()
|
s.Config, err = s.NewConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -72,7 +72,7 @@ type testFunction struct {
|
||||||
Fn func(*testing.T)
|
Fn func(*testing.T)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Suite) testFuncs(t testing.TB) (funcs []testFunction) {
|
func (s *Suite[C]) testFuncs(t testing.TB) (funcs []testFunction) {
|
||||||
tpe := reflect.TypeOf(s)
|
tpe := reflect.TypeOf(s)
|
||||||
v := reflect.ValueOf(s)
|
v := reflect.ValueOf(s)
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ type benchmarkFunction struct {
|
||||||
Fn func(*testing.B)
|
Fn func(*testing.B)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Suite) benchmarkFuncs(t testing.TB) (funcs []benchmarkFunction) {
|
func (s *Suite[C]) benchmarkFuncs(t testing.TB) (funcs []benchmarkFunction) {
|
||||||
tpe := reflect.TypeOf(s)
|
tpe := reflect.TypeOf(s)
|
||||||
v := reflect.ValueOf(s)
|
v := reflect.ValueOf(s)
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ func (s *Suite) benchmarkFuncs(t testing.TB) (funcs []benchmarkFunction) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunBenchmarks executes all defined benchmarks as subtests of b.
|
// RunBenchmarks executes all defined benchmarks as subtests of b.
|
||||||
func (s *Suite) RunBenchmarks(b *testing.B) {
|
func (s *Suite[C]) RunBenchmarks(b *testing.B) {
|
||||||
var err error
|
var err error
|
||||||
s.Config, err = s.NewConfig()
|
s.Config, err = s.NewConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -163,7 +163,7 @@ func (s *Suite) RunBenchmarks(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Suite) create(t testing.TB) restic.Backend {
|
func (s *Suite[C]) create(t testing.TB) restic.Backend {
|
||||||
be, err := s.Create(s.Config)
|
be, err := s.Create(s.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -171,7 +171,7 @@ func (s *Suite) create(t testing.TB) restic.Backend {
|
||||||
return be
|
return be
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Suite) open(t testing.TB) restic.Backend {
|
func (s *Suite[C]) open(t testing.TB) restic.Backend {
|
||||||
be, err := s.Open(s.Config)
|
be, err := s.Open(s.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -179,7 +179,7 @@ func (s *Suite) open(t testing.TB) restic.Backend {
|
||||||
return be
|
return be
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Suite) close(t testing.TB, be restic.Backend) {
|
func (s *Suite[C]) close(t testing.TB, be restic.Backend) {
|
||||||
err := be.Close()
|
err := be.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -38,7 +38,7 @@ func beTest(ctx context.Context, be restic.Backend, h restic.Handle) (bool, erro
|
||||||
|
|
||||||
// TestCreateWithConfig tests that creating a backend in a location which already
|
// TestCreateWithConfig tests that creating a backend in a location which already
|
||||||
// has a config file fails.
|
// has a config file fails.
|
||||||
func (s *Suite) TestCreateWithConfig(t *testing.T) {
|
func (s *Suite[C]) TestCreateWithConfig(t *testing.T) {
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
defer s.close(t, b)
|
defer s.close(t, b)
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func (s *Suite) TestCreateWithConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestLocation tests that a location string is returned.
|
// TestLocation tests that a location string is returned.
|
||||||
func (s *Suite) TestLocation(t *testing.T) {
|
func (s *Suite[C]) TestLocation(t *testing.T) {
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
defer s.close(t, b)
|
defer s.close(t, b)
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ func (s *Suite) TestLocation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestConfig saves and loads a config from the backend.
|
// TestConfig saves and loads a config from the backend.
|
||||||
func (s *Suite) TestConfig(t *testing.T) {
|
func (s *Suite[C]) TestConfig(t *testing.T) {
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
defer s.close(t, b)
|
defer s.close(t, b)
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ func (s *Suite) TestConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestLoad tests the backend's Load function.
|
// TestLoad tests the backend's Load function.
|
||||||
func (s *Suite) TestLoad(t *testing.T) {
|
func (s *Suite[C]) TestLoad(t *testing.T) {
|
||||||
seedRand(t)
|
seedRand(t)
|
||||||
|
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
|
@ -223,7 +223,7 @@ func (s *Suite) TestLoad(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestList makes sure that the backend implements List() pagination correctly.
|
// TestList makes sure that the backend implements List() pagination correctly.
|
||||||
func (s *Suite) TestList(t *testing.T) {
|
func (s *Suite[C]) TestList(t *testing.T) {
|
||||||
seedRand(t)
|
seedRand(t)
|
||||||
|
|
||||||
numTestFiles := rand.Intn(20) + 20
|
numTestFiles := rand.Intn(20) + 20
|
||||||
|
@ -326,7 +326,7 @@ func (s *Suite) TestList(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestListCancel tests that the context is respected and the error is returned by List.
|
// TestListCancel tests that the context is respected and the error is returned by List.
|
||||||
func (s *Suite) TestListCancel(t *testing.T) {
|
func (s *Suite[C]) TestListCancel(t *testing.T) {
|
||||||
seedRand(t)
|
seedRand(t)
|
||||||
|
|
||||||
numTestFiles := 5
|
numTestFiles := 5
|
||||||
|
@ -466,7 +466,7 @@ func (ec errorCloser) Rewind() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSave tests saving data in the backend.
|
// TestSave tests saving data in the backend.
|
||||||
func (s *Suite) TestSave(t *testing.T) {
|
func (s *Suite[C]) TestSave(t *testing.T) {
|
||||||
seedRand(t)
|
seedRand(t)
|
||||||
|
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
|
@ -582,7 +582,7 @@ func (r *incompleteByteReader) Length() int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSaveError tests saving data in the backend.
|
// TestSaveError tests saving data in the backend.
|
||||||
func (s *Suite) TestSaveError(t *testing.T) {
|
func (s *Suite[C]) TestSaveError(t *testing.T) {
|
||||||
seedRand(t)
|
seedRand(t)
|
||||||
|
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
|
@ -621,7 +621,7 @@ func (b *wrongByteReader) Hash() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSaveWrongHash tests that uploads with a wrong hash fail
|
// TestSaveWrongHash tests that uploads with a wrong hash fail
|
||||||
func (s *Suite) TestSaveWrongHash(t *testing.T) {
|
func (s *Suite[C]) TestSaveWrongHash(t *testing.T) {
|
||||||
seedRand(t)
|
seedRand(t)
|
||||||
|
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
|
@ -679,7 +679,7 @@ func testLoad(b restic.Backend, h restic.Handle) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Suite) delayedRemove(t testing.TB, be restic.Backend, handles ...restic.Handle) error {
|
func (s *Suite[C]) delayedRemove(t testing.TB, be restic.Backend, handles ...restic.Handle) error {
|
||||||
// Some backend (swift, I'm looking at you) may implement delayed
|
// Some backend (swift, I'm looking at you) may implement delayed
|
||||||
// removal of data. Let's wait a bit if this happens.
|
// removal of data. Let's wait a bit if this happens.
|
||||||
|
|
||||||
|
@ -746,7 +746,7 @@ func delayedList(t testing.TB, b restic.Backend, tpe restic.FileType, max int, m
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestBackend tests all functions of the backend.
|
// TestBackend tests all functions of the backend.
|
||||||
func (s *Suite) TestBackend(t *testing.T) {
|
func (s *Suite[C]) TestBackend(t *testing.T) {
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
defer s.close(t, b)
|
defer s.close(t, b)
|
||||||
|
|
||||||
|
@ -867,7 +867,7 @@ func (s *Suite) TestBackend(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestZZZDelete tests the Delete function. The name ensures that this test is executed last.
|
// TestZZZDelete tests the Delete function. The name ensures that this test is executed last.
|
||||||
func (s *Suite) TestZZZDelete(t *testing.T) {
|
func (s *Suite[C]) TestZZZDelete(t *testing.T) {
|
||||||
if !test.TestCleanupTempDirs {
|
if !test.TestCleanupTempDirs {
|
||||||
t.Skipf("not removing backend, TestCleanupTempDirs is false")
|
t.Skipf("not removing backend, TestCleanupTempDirs is false")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue