2016-01-23 16:42:26 +00:00
|
|
|
package test_test
|
2016-01-23 16:08:03 +00:00
|
|
|
|
2016-01-23 16:42:26 +00:00
|
|
|
import (
|
2017-06-03 15:39:57 +00:00
|
|
|
"context"
|
2016-08-31 20:51:35 +00:00
|
|
|
"restic"
|
2016-09-01 20:17:37 +00:00
|
|
|
"restic/errors"
|
2017-05-01 20:23:46 +00:00
|
|
|
"testing"
|
2016-01-23 16:42:26 +00:00
|
|
|
|
2016-02-14 14:29:28 +00:00
|
|
|
"restic/backend/mem"
|
|
|
|
"restic/backend/test"
|
2016-01-23 16:42:26 +00:00
|
|
|
)
|
|
|
|
|
2017-05-01 20:23:46 +00:00
|
|
|
//go:generate go run generate_test_list.go
|
2016-01-23 16:42:26 +00:00
|
|
|
|
2017-05-01 20:23:46 +00:00
|
|
|
type memConfig struct {
|
|
|
|
be restic.Backend
|
|
|
|
}
|
2016-01-23 16:42:26 +00:00
|
|
|
|
2017-05-13 19:37:07 +00:00
|
|
|
func newTestSuite(t testing.TB) *test.Suite {
|
|
|
|
return &test.Suite{
|
2017-05-01 20:23:46 +00:00
|
|
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
|
|
|
NewConfig: func() (interface{}, error) {
|
|
|
|
return &memConfig{}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
// CreateFn is a function that creates a temporary repository for the tests.
|
|
|
|
Create: func(cfg interface{}) (restic.Backend, error) {
|
|
|
|
c := cfg.(*memConfig)
|
|
|
|
if c.be != nil {
|
2017-06-03 15:39:57 +00:00
|
|
|
ok, err := c.be.Test(context.TODO(), restic.Handle{Type: restic.ConfigFile})
|
2017-05-01 20:23:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
return nil, errors.New("config already exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.be = mem.New()
|
|
|
|
return c.be, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
// OpenFn is a function that opens a previously created temporary repository.
|
|
|
|
Open: func(cfg interface{}) (restic.Backend, error) {
|
|
|
|
c := cfg.(*memConfig)
|
|
|
|
if c.be == nil {
|
|
|
|
c.be = mem.New()
|
|
|
|
}
|
|
|
|
return c.be, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
// CleanupFn removes data created during the tests.
|
|
|
|
Cleanup: func(cfg interface{}) error {
|
|
|
|
// no cleanup needed
|
|
|
|
return nil
|
|
|
|
},
|
2016-01-23 16:42:26 +00:00
|
|
|
}
|
2017-05-13 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSuiteBackendMem(t *testing.T) {
|
|
|
|
newTestSuite(t).RunTests(t)
|
|
|
|
}
|
2016-01-23 16:42:26 +00:00
|
|
|
|
2017-05-13 19:37:07 +00:00
|
|
|
func BenchmarkSuiteBackendMem(b *testing.B) {
|
|
|
|
newTestSuite(b).RunBenchmarks(b)
|
2016-01-23 16:42:26 +00:00
|
|
|
}
|