1
0
mirror of https://github.com/restic/restic.git synced 2024-07-04 09:00:54 +02:00
restic/internal/backend/mem/mem_backend_test.go

66 lines
1.5 KiB
Go
Raw Normal View History

2016-01-23 19:19:26 +01:00
package mem_test
import (
2017-06-03 17:39:57 +02:00
"context"
2017-05-01 22:56:05 +02:00
"testing"
2016-08-31 22:51:35 +02:00
2017-07-23 14:21:03 +02:00
"github.com/restic/restic/internal/errors"
2017-07-24 17:42:25 +02:00
"github.com/restic/restic/internal/restic"
2017-07-23 14:21:03 +02:00
"github.com/restic/restic/internal/backend/mem"
"github.com/restic/restic/internal/backend/test"
)
2017-05-01 22:56:05 +02:00
type memConfig struct {
be restic.Backend
}
func newTestSuite() *test.Suite[*memConfig] {
return &test.Suite[*memConfig]{
2017-05-01 22:56:05 +02:00
// NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (**memConfig, error) {
cfg := &memConfig{}
return &cfg, nil
2017-05-01 22:56:05 +02:00
},
// CreateFn is a function that creates a temporary repository for the tests.
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 22:56:05 +02:00
return nil, err
}
if err == nil {
2017-05-01 22:56:05 +02:00
return nil, errors.New("config already exists")
}
}
cfg.be = mem.New()
return cfg.be, nil
2017-05-01 22:56:05 +02:00
},
// OpenFn is a function that opens a previously created temporary repository.
Open: func(cfg *memConfig) (restic.Backend, error) {
if cfg.be == nil {
cfg.be = mem.New()
2017-05-01 22:56:05 +02:00
}
return cfg.be, nil
2017-05-01 22:56:05 +02:00
},
// CleanupFn removes data created during the tests.
Cleanup: func(cfg *memConfig) error {
2017-05-01 22:56:05 +02:00
// no cleanup needed
return nil
},
}
2017-05-13 21:47:01 +02:00
}
func TestSuiteBackendMem(t *testing.T) {
newTestSuite().RunTests(t)
}
2017-05-13 21:47:01 +02:00
func BenchmarkSuiteBackendMem(t *testing.B) {
newTestSuite().RunBenchmarks(t)
}