2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-02 11:46:36 +00:00
restic/internal/backend/mem/mem_backend_test.go

68 lines
1.4 KiB
Go
Raw Normal View History

2016-01-23 18:19:26 +00:00
package mem_test
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"
2017-07-23 12:21:03 +00:00
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/backend/mem"
"github.com/restic/restic/internal/backend/test"
)
2017-05-01 20:56:05 +00:00
type memConfig struct {
be restic.Backend
}
2017-05-13 19:47:01 +00:00
func newTestSuite() *test.Suite {
return &test.Suite{
2017-05-01 20:56:05 +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:56:05 +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:47:01 +00:00
}
func TestSuiteBackendMem(t *testing.T) {
newTestSuite().RunTests(t)
}
2017-05-13 19:47:01 +00:00
func BenchmarkSuiteBackendMem(t *testing.B) {
newTestSuite().RunBenchmarks(t)
}