From 1f583b3d8e5c8029636527305dbdc06024cecda0 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 18 Dec 2020 23:53:15 +0100 Subject: [PATCH] backend: test that incomplete uploads fail --- internal/backend/test/tests.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/internal/backend/test/tests.go b/internal/backend/test/tests.go index 92a63fba2..a35b75e5a 100644 --- a/internal/backend/test/tests.go +++ b/internal/backend/test/tests.go @@ -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 { name string data string