2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 23:06:32 +00:00
restic/internal/backend/local/local_test.go

62 lines
1.4 KiB
Go
Raw Normal View History

2016-01-23 16:08:03 +00:00
package local_test
import (
"io/ioutil"
2017-05-01 20:46:51 +00:00
"testing"
2016-01-23 16:08:03 +00:00
2017-07-23 12:21:03 +00:00
"github.com/restic/restic/internal/backend/local"
"github.com/restic/restic/internal/backend/test"
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/test"
2016-01-23 16:08:03 +00:00
)
2017-05-13 19:45:41 +00:00
func newTestSuite(t testing.TB) *test.Suite {
return &test.Suite{
2017-05-01 20:46:51 +00:00
// NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (interface{}, error) {
dir, err := ioutil.TempDir(TestTempDir, "restic-test-local-")
if err != nil {
t.Fatal(err)
}
t.Logf("create new backend at %v", dir)
cfg := local.Config{
Path: dir,
}
return cfg, nil
},
// CreateFn is a function that creates a temporary repository for the tests.
Create: func(config interface{}) (restic.Backend, error) {
cfg := config.(local.Config)
return local.Create(cfg)
},
// OpenFn is a function that opens a previously created temporary repository.
Open: func(config interface{}) (restic.Backend, error) {
cfg := config.(local.Config)
return local.Open(cfg)
},
// CleanupFn removes data created during the tests.
Cleanup: func(config interface{}) error {
cfg := config.(local.Config)
if !TestCleanupTempDirs {
t.Logf("leaving test backend dir at %v", cfg.Path)
}
RemoveAll(t, cfg.Path)
2016-01-23 16:08:03 +00:00
return nil
2017-05-01 20:46:51 +00:00
},
2016-01-23 16:08:03 +00:00
}
2017-05-13 19:45:41 +00:00
}
func TestBackend(t *testing.T) {
newTestSuite(t).RunTests(t)
}
2017-05-01 20:46:51 +00:00
2017-05-13 19:45:41 +00:00
func BenchmarkBackend(t *testing.B) {
newTestSuite(t).RunBenchmarks(t)
2016-01-23 16:08:03 +00:00
}