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

@@ -6,6 +6,7 @@ import (
"github.com/restic/restic"
"github.com/restic/restic/backend"
. "github.com/restic/restic/test"
)
func TestCache(t *testing.T) {
@@ -15,45 +16,45 @@ func TestCache(t *testing.T) {
server.SetKey(key)
cache, err := restic.NewCache(server)
ok(t, err)
OK(t, err)
arch, err := restic.NewArchiver(server)
ok(t, err)
OK(t, err)
// archive some files, this should automatically cache all blobs from the snapshot
_, id, err := arch.Snapshot(nil, []string{*benchArchiveDirectory}, nil)
// try to load map from cache
rd, err := cache.Load(backend.Snapshot, "blobs", id)
ok(t, err)
OK(t, err)
dec := json.NewDecoder(rd)
m := &restic.Map{}
err = dec.Decode(m)
ok(t, err)
OK(t, err)
// remove cached blob list
ok(t, cache.Purge(backend.Snapshot, "blobs", id))
OK(t, cache.Purge(backend.Snapshot, "blobs", id))
// load map from cache again, this should fail
rd, err = cache.Load(backend.Snapshot, "blobs", id)
assert(t, err != nil, "Expected failure did not occur")
Assert(t, err != nil, "Expected failure did not occur")
// recreate cached blob list
err = cache.RefreshSnapshots(server, nil)
ok(t, err)
OK(t, err)
// load map from cache again
rd, err = cache.Load(backend.Snapshot, "blobs", id)
ok(t, err)
OK(t, err)
dec = json.NewDecoder(rd)
m2 := &restic.Map{}
err = dec.Decode(m2)
ok(t, err)
OK(t, err)
// compare maps
assert(t, m.Equals(m2), "Maps are not equal")
Assert(t, m.Equals(m2), "Maps are not equal")
}