1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-23 08:16:36 +00:00

mem: Convert to test suite

This commit is contained in:
Alexander Neumann 2017-05-01 22:56:05 +02:00
parent 3678d34b16
commit 3250fdc2ca
2 changed files with 47 additions and 114 deletions

View file

@ -1,87 +0,0 @@
// DO NOT EDIT, AUTOMATICALLY GENERATED
package mem_test
import (
"testing"
"restic/backend/test"
)
var SkipMessage string
func TestMemBackendCreate(t *testing.T) {
if SkipMessage != "" {
t.Skip(SkipMessage)
}
test.TestCreate(t)
}
func TestMemBackendOpen(t *testing.T) {
if SkipMessage != "" {
t.Skip(SkipMessage)
}
test.TestOpen(t)
}
func TestMemBackendCreateWithConfig(t *testing.T) {
if SkipMessage != "" {
t.Skip(SkipMessage)
}
test.TestCreateWithConfig(t)
}
func TestMemBackendLocation(t *testing.T) {
if SkipMessage != "" {
t.Skip(SkipMessage)
}
test.TestLocation(t)
}
func TestMemBackendConfig(t *testing.T) {
if SkipMessage != "" {
t.Skip(SkipMessage)
}
test.TestConfig(t)
}
func TestMemBackendLoad(t *testing.T) {
if SkipMessage != "" {
t.Skip(SkipMessage)
}
test.TestLoad(t)
}
func TestMemBackendSave(t *testing.T) {
if SkipMessage != "" {
t.Skip(SkipMessage)
}
test.TestSave(t)
}
func TestMemBackendSaveFilenames(t *testing.T) {
if SkipMessage != "" {
t.Skip(SkipMessage)
}
test.TestSaveFilenames(t)
}
func TestMemBackendBackend(t *testing.T) {
if SkipMessage != "" {
t.Skip(SkipMessage)
}
test.TestBackend(t)
}
func TestMemBackendDelete(t *testing.T) {
if SkipMessage != "" {
t.Skip(SkipMessage)
}
test.TestDelete(t)
}
func TestMemBackendCleanup(t *testing.T) {
if SkipMessage != "" {
t.Skip(SkipMessage)
}
test.TestCleanup(t)
}

View file

@ -2,6 +2,7 @@ package mem_test
import ( import (
"restic" "restic"
"testing"
"restic/errors" "restic/errors"
@ -9,31 +10,50 @@ import (
"restic/backend/test" "restic/backend/test"
) )
var be restic.Backend type memConfig struct {
be restic.Backend
//go:generate go run ../test/generate_backend_tests.go }
func init() { func TestSuiteBackendMem(t *testing.T) {
test.CreateFn = func() (restic.Backend, error) { suite := test.Suite{
if be != nil { // NewConfig returns a config for a new temporary backend that will be used in tests.
return nil, errors.New("temporary memory backend dir already exists") NewConfig: func() (interface{}, error) {
} return &memConfig{}, nil
},
be = mem.New()
// CreateFn is a function that creates a temporary repository for the tests.
return be, nil Create: func(cfg interface{}) (restic.Backend, error) {
} c := cfg.(*memConfig)
if c.be != nil {
test.OpenFn = func() (restic.Backend, error) { ok, err := c.be.Test(restic.Handle{Type: restic.ConfigFile})
if be == nil { if err != nil {
return nil, errors.New("repository not initialized") return nil, err
} }
return be, nil if ok {
} return nil, errors.New("config already exists")
}
test.CleanupFn = func() error { }
be = nil
return nil 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
},
}
suite.RunTests(t)
} }