restic/src/restic/backend/local/local_test.go

56 lines
1.2 KiB
Go
Raw Normal View History

2016-01-23 17:08:03 +01:00
package local_test
import (
"io/ioutil"
2016-08-31 22:51:35 +02:00
"restic"
2017-05-01 22:46:51 +02:00
"testing"
2016-01-23 17:08:03 +01:00
"restic/backend/local"
"restic/backend/test"
2017-05-01 22:46:51 +02:00
. "restic/test"
2016-01-23 17:08:03 +01:00
)
2017-05-01 22:46:51 +02:00
func TestBackend(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) {
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 17:08:03 +01:00
return nil
2017-05-01 22:46:51 +02:00
},
2016-01-23 17:08:03 +01:00
}
2017-05-01 22:46:51 +02:00
suite.RunTests(t)
2016-01-23 17:08:03 +01:00
}