restic/src/restic/backend/test/tests_test.go

61 lines
1.2 KiB
Go
Raw Normal View History

package test_test
2016-01-23 17:08:03 +01:00
import (
2016-08-31 22:51:35 +02:00
"restic"
2016-09-01 22:17:37 +02:00
"restic/errors"
2017-05-01 22:23:46 +02:00
"testing"
"restic/backend/mem"
"restic/backend/test"
)
2017-05-01 22:23:46 +02:00
//go:generate go run generate_test_list.go
2017-05-01 22:23:46 +02:00
type memConfig struct {
be restic.Backend
}
2017-05-01 22:23:46 +02:00
func TestSuiteBackendMem(t *testing.T) {
suite := test.Suite{
// 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 {
ok, err := c.be.Test(restic.Handle{Type: restic.ConfigFile})
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-01 22:23:46 +02:00
suite.RunTests(t)
}