tests: Simplify key handling

This commit is contained in:
Alexander Neumann 2015-05-03 16:36:52 +02:00
parent 062c328f2d
commit 1cedff0e9e
8 changed files with 20 additions and 61 deletions

View file

@ -13,7 +13,7 @@ import (
"github.com/restic/restic/server"
)
var TestPassword = "foobar"
var TestPassword = flag.String("test.password", "", `use this password for repositories created during tests (default: "geheim")`)
var TestCleanup = flag.Bool("test.cleanup", true, "clean up after running tests (remove local backend directory with all content)")
var TestTempDir = flag.String("test.tempdir", "", "use this directory for temporary storage (default: system temp dir)")
@ -25,11 +25,13 @@ func SetupBackend(t testing.TB) *server.Server {
b, err := local.Create(filepath.Join(tempdir, "repo"))
OK(t, err)
// set cache dir
// set cache dir below temp dir
err = os.Setenv("RESTIC_CACHE", filepath.Join(tempdir, "cache"))
OK(t, err)
return server.NewServer(b)
s := server.NewServer(b)
OK(t, s.CreateKey(*TestPassword))
return s
}
func TeardownBackend(t testing.TB, s *server.Server) {
@ -42,13 +44,6 @@ func TeardownBackend(t testing.TB, s *server.Server) {
OK(t, s.Delete())
}
func SetupKey(t testing.TB, s *server.Server, password string) *server.Key {
k, err := server.CreateKey(s, password)
OK(t, err)
return k
}
func SnapshotDir(t testing.TB, server *server.Server, path string, parent backend.ID) *restic.Snapshot {
arch := restic.NewArchiver(server)
sn, _, err := arch.Snapshot(nil, []string{path}, parent)