mirror of https://github.com/restic/restic.git
backend/test: Loose requirement about early error
This commit is contained in:
parent
c5244abad9
commit
f3f6924b61
|
@ -113,12 +113,15 @@ func (s *Suite) TestLoad(t *testing.T) {
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
defer s.close(t, b)
|
defer s.close(t, b)
|
||||||
|
|
||||||
_, err := b.Load(restic.Handle{}, 0, 0)
|
rd, err := b.Load(restic.Handle{}, 0, 0)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Load() did not return an error for invalid handle")
|
t.Fatalf("Load() did not return an error for invalid handle")
|
||||||
}
|
}
|
||||||
|
if rd != nil {
|
||||||
|
rd.Close()
|
||||||
|
}
|
||||||
|
|
||||||
_, err = b.Load(restic.Handle{Type: restic.DataFile, Name: "foobar"}, 0, 0)
|
err = testLoad(b, restic.Handle{Type: restic.DataFile, Name: "foobar"}, 0, 0)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Load() did not return an error for non-existing blob")
|
t.Fatalf("Load() did not return an error for non-existing blob")
|
||||||
}
|
}
|
||||||
|
@ -136,7 +139,7 @@ func (s *Suite) TestLoad(t *testing.T) {
|
||||||
|
|
||||||
t.Logf("saved %d bytes as %v", length, handle)
|
t.Logf("saved %d bytes as %v", length, handle)
|
||||||
|
|
||||||
rd, err := b.Load(handle, 100, -1)
|
rd, err = b.Load(handle, 100, -1)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Load() returned no error for negative offset!")
|
t.Fatalf("Load() returned no error for negative offset!")
|
||||||
}
|
}
|
||||||
|
@ -416,6 +419,21 @@ func store(t testing.TB, b restic.Backend, tpe restic.FileType, data []byte) res
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// testLoad loads a blob (but discards its contents).
|
||||||
|
func testLoad(b restic.Backend, h restic.Handle, length int, offset int64) error {
|
||||||
|
rd, err := b.Load(h, 0, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(ioutil.Discard, rd)
|
||||||
|
cerr := rd.Close()
|
||||||
|
if err == nil {
|
||||||
|
err = cerr
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// TestBackend tests all functions of the backend.
|
// TestBackend tests all functions of the backend.
|
||||||
func (s *Suite) TestBackend(t *testing.T) {
|
func (s *Suite) TestBackend(t *testing.T) {
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
|
@ -441,8 +459,8 @@ func (s *Suite) TestBackend(t *testing.T) {
|
||||||
test.Assert(t, err != nil, "blob data could be extracted before creation")
|
test.Assert(t, err != nil, "blob data could be extracted before creation")
|
||||||
|
|
||||||
// try to read not existing blob
|
// try to read not existing blob
|
||||||
_, err = b.Load(h, 0, 0)
|
err = testLoad(b, h, 0, 0)
|
||||||
test.Assert(t, err != nil, "blob reader could be obtained before creation")
|
test.Assert(t, err != nil, "blob could be read before creation")
|
||||||
|
|
||||||
// try to get string out, should fail
|
// try to get string out, should fail
|
||||||
ret, err = b.Test(h)
|
ret, err = b.Test(h)
|
||||||
|
|
Loading…
Reference in New Issue