2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-23 05:12:10 +00:00

Merge pull request #3248 from MichaelEischer/backend-cleanups

Backend code and test cleanups
This commit is contained in:
Alexander Neumann 2021-01-30 21:37:33 +01:00 committed by GitHub
commit f647614e24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -81,14 +81,14 @@ func (be *MemoryBackend) Save(ctx context.Context, h restic.Handle, rd restic.Re
return err
}
be.data[h] = buf
debug.Log("saved %v bytes at %v", len(buf), h)
// sanity check
if int64(len(buf)) != rd.Length() {
return errors.Errorf("wrote %d bytes instead of the expected %d bytes", len(buf), rd.Length())
}
be.data[h] = buf
debug.Log("saved %v bytes at %v", len(buf), h)
return ctx.Err()
}

View File

@ -577,13 +577,15 @@ func (s *Suite) TestSaveError(t *testing.T) {
}()
length := rand.Intn(1<<23) + 200000
data := test.Random(23, length)
data := test.Random(24, 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)})
// try to delete possible leftovers
_ = s.delayedRemove(t, b, h)
if err == nil {
t.Fatal("incomplete upload did not fail")
}