2016-01-23 18:19:26 +00:00
|
|
|
package mem_test
|
2016-01-23 16:42:26 +00:00
|
|
|
|
|
|
|
import (
|
2017-06-03 15:39:57 +00:00
|
|
|
"context"
|
2017-05-01 20:56:05 +00:00
|
|
|
"testing"
|
2016-08-31 20:51:35 +00:00
|
|
|
|
2017-07-23 12:21:03 +00:00
|
|
|
"github.com/restic/restic/internal/errors"
|
2017-07-24 15:42:25 +00:00
|
|
|
"github.com/restic/restic/internal/restic"
|
2017-07-23 12:21:03 +00:00
|
|
|
|
|
|
|
"github.com/restic/restic/internal/backend/mem"
|
|
|
|
"github.com/restic/restic/internal/backend/test"
|
2016-01-23 16:42:26 +00:00
|
|
|
)
|
|
|
|
|
2017-05-01 20:56:05 +00:00
|
|
|
type memConfig struct {
|
|
|
|
be restic.Backend
|
|
|
|
}
|
2016-01-23 16:42:26 +00:00
|
|
|
|
2023-04-21 19:06:56 +00:00
|
|
|
func newTestSuite() *test.Suite[*memConfig] {
|
|
|
|
return &test.Suite[*memConfig]{
|
2017-05-01 20:56:05 +00:00
|
|
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
2023-04-21 19:06:56 +00:00
|
|
|
NewConfig: func() (*memConfig, error) {
|
2017-05-01 20:56:05 +00:00
|
|
|
return &memConfig{}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
// CreateFn is a function that creates a temporary repository for the tests.
|
2023-04-21 19:06:56 +00:00
|
|
|
Create: func(cfg *memConfig) (restic.Backend, error) {
|
|
|
|
if cfg.be != nil {
|
|
|
|
_, err := cfg.be.Stat(context.TODO(), restic.Handle{Type: restic.ConfigFile})
|
|
|
|
if err != nil && !cfg.be.IsNotExist(err) {
|
2017-05-01 20:56:05 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-12-03 10:28:10 +00:00
|
|
|
if err == nil {
|
2017-05-01 20:56:05 +00:00
|
|
|
return nil, errors.New("config already exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-21 19:06:56 +00:00
|
|
|
cfg.be = mem.New()
|
|
|
|
return cfg.be, nil
|
2017-05-01 20:56:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// OpenFn is a function that opens a previously created temporary repository.
|
2023-04-21 19:06:56 +00:00
|
|
|
Open: func(cfg *memConfig) (restic.Backend, error) {
|
|
|
|
if cfg.be == nil {
|
|
|
|
cfg.be = mem.New()
|
2017-05-01 20:56:05 +00:00
|
|
|
}
|
2023-04-21 19:06:56 +00:00
|
|
|
return cfg.be, nil
|
2017-05-01 20:56:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// CleanupFn removes data created during the tests.
|
2023-04-21 19:06:56 +00:00
|
|
|
Cleanup: func(cfg *memConfig) error {
|
2017-05-01 20:56:05 +00:00
|
|
|
// no cleanup needed
|
|
|
|
return nil
|
|
|
|
},
|
2016-01-23 16:42:26 +00:00
|
|
|
}
|
2017-05-13 19:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSuiteBackendMem(t *testing.T) {
|
|
|
|
newTestSuite().RunTests(t)
|
|
|
|
}
|
2016-01-23 16:42:26 +00:00
|
|
|
|
2017-05-13 19:47:01 +00:00
|
|
|
func BenchmarkSuiteBackendMem(t *testing.B) {
|
|
|
|
newTestSuite().RunBenchmarks(t)
|
2016-01-23 16:42:26 +00:00
|
|
|
}
|