From fb62da17480611b97e047fd342beb23c9e1e17c0 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 27 Jan 2018 13:06:15 +0000 Subject: [PATCH] Make backend tests more helpful * In TestList check that backend is empty first * Improve error message in TestBackend --- internal/backend/test/tests.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/backend/test/tests.go b/internal/backend/test/tests.go index 17ba28dae..bd681ad3a 100644 --- a/internal/backend/test/tests.go +++ b/internal/backend/test/tests.go @@ -249,6 +249,19 @@ func (s *Suite) TestList(t *testing.T) { b := s.open(t) defer s.close(t, b) + // Check that the backend is empty to start with + var found []string + err := b.List(context.TODO(), restic.DataFile, func(fi restic.FileInfo) error { + found = append(found, fi.Name) + return nil + }) + if err != nil { + t.Fatalf("List returned error %v", err) + } + if found != nil { + t.Fatalf("backend not empty at start of test - contains: %v", found) + } + list1 := make(map[restic.ID]int64) for i := 0; i < numTestFiles; i++ { @@ -324,7 +337,7 @@ func (s *Suite) TestList(t *testing.T) { handles = append(handles, restic.Handle{Type: restic.DataFile, Name: id.String()}) } - err := s.delayedRemove(t, b, handles...) + err = s.delayedRemove(t, b, handles...) if err != nil { t.Fatal(err) } @@ -784,7 +797,7 @@ func (s *Suite) TestBackend(t *testing.T) { // create blob h := restic.Handle{Type: tpe, Name: ts.id} err := b.Save(context.TODO(), h, strings.NewReader(ts.data)) - test.Assert(t, err != nil, "expected error for %v, got %v", h, err) + test.Assert(t, err != nil, "backend has allowed overwrite of existing blob: expected error for %v, got %v", h, err) // remove and recreate err = s.delayedRemove(t, b, h)