Use package "restic/test"

This commit is contained in:
Alexander Neumann 2015-04-09 21:15:48 +02:00
parent a2514425a3
commit 4f4f3c421a
24 changed files with 248 additions and 403 deletions

View file

@ -7,16 +7,17 @@ import (
"testing"
"github.com/restic/restic/backend/local"
. "github.com/restic/restic/test"
)
var testCleanup = flag.Bool("test.cleanup", true, "clean up after running tests (remove local backend directory with all content)")
func setupLocalBackend(t *testing.T) *local.Local {
tempdir, err := ioutil.TempDir("", "restic-test-")
ok(t, err)
OK(t, err)
b, err := local.Create(tempdir)
ok(t, err)
OK(t, err)
t.Logf("created local backend at %s", tempdir)
@ -29,14 +30,14 @@ func teardownLocalBackend(t *testing.T, b *local.Local) {
return
}
ok(t, b.Delete())
OK(t, b.Delete())
}
func TestLocalBackend(t *testing.T) {
// test for non-existing backend
b, err := local.Open("/invalid-restic-test")
assert(t, err != nil, "opening invalid repository at /invalid-restic-test should have failed, but err is nil")
assert(t, b == nil, fmt.Sprintf("opening invalid repository at /invalid-restic-test should have failed, but b is not nil: %v", b))
Assert(t, err != nil, "opening invalid repository at /invalid-restic-test should have failed, but err is nil")
Assert(t, b == nil, fmt.Sprintf("opening invalid repository at /invalid-restic-test should have failed, but b is not nil: %v", b))
s := setupLocalBackend(t)
defer teardownLocalBackend(t, s)
@ -50,9 +51,9 @@ func TestLocalBackendCreationFailures(t *testing.T) {
// test failure to create a new repository at the same location
b2, err := local.Create(b.Location())
assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
// test failure to create a new repository at the same location without a config file
b2, err = local.Create(b.Location())
assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
}