2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-30 08:44:02 +00:00
restic/internal/backend/test/tests_test.go

67 lines
1.5 KiB
Go
Raw Normal View History

package test_test
2016-01-23 16:08:03 +00:00
import (
2017-06-03 15:39:57 +00:00
"context"
2017-05-01 20:23:46 +00:00
"testing"
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"
)
2017-05-01 20:23:46 +00:00
type memConfig struct {
be restic.Backend
}
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
},
}
2017-05-13 19:37:07 +00:00
}
func TestSuiteBackendMem(t *testing.T) {
newTestSuite(t).RunTests(t)
}
2017-05-13 19:37:07 +00:00
func BenchmarkSuiteBackendMem(b *testing.B) {
newTestSuite(b).RunBenchmarks(b)
}