2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-16 01:57:10 +00:00

backend: test that incomplete uploads fail

This commit is contained in:
Michael Eischer 2020-12-18 23:53:15 +01:00 committed by Alexander Neumann
parent c73316a111
commit 1f583b3d8e

View File

@ -557,6 +557,38 @@ func (s *Suite) TestSave(t *testing.T) {
} }
} }
type incompleteByteReader struct {
restic.ByteReader
}
func (r *incompleteByteReader) Length() int64 {
return r.ByteReader.Length() + 42
}
// TestSaveError tests saving data in the backend.
func (s *Suite) TestSaveError(t *testing.T) {
seedRand(t)
b := s.open(t)
defer func() {
// rclone will report an error when closing the backend. We have to ignore it
// otherwise this test will always fail
_ = b.Close()
}()
length := rand.Intn(1<<23) + 200000
data := test.Random(23, length)
var id restic.ID
copy(id[:], data)
// test that incomplete uploads fail
h := restic.Handle{Type: restic.PackFile, Name: id.String()}
err := b.Save(context.TODO(), h, &incompleteByteReader{ByteReader: *restic.NewByteReader(data)})
if err == nil {
t.Fatal("incomplete upload did not fail")
}
}
var filenameTests = []struct { var filenameTests = []struct {
name string name string
data string data string