Make backend tests more helpful

* In TestList check that backend is empty first
  * Improve error message in TestBackend
This commit is contained in:
Nick Craig-Wood 2018-01-27 13:06:15 +00:00
parent e706f1a8d1
commit fb62da1748
1 changed files with 15 additions and 2 deletions

View File

@ -249,6 +249,19 @@ func (s *Suite) TestList(t *testing.T) {
b := s.open(t) b := s.open(t)
defer s.close(t, b) 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) list1 := make(map[restic.ID]int64)
for i := 0; i < numTestFiles; i++ { 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()}) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -784,7 +797,7 @@ func (s *Suite) TestBackend(t *testing.T) {
// create blob // create blob
h := restic.Handle{Type: tpe, Name: ts.id} h := restic.Handle{Type: tpe, Name: ts.id}
err := b.Save(context.TODO(), h, strings.NewReader(ts.data)) 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 // remove and recreate
err = s.delayedRemove(t, b, h) err = s.delayedRemove(t, b, h)