diff --git a/src/restic/checker/checker_test.go b/src/restic/checker/checker_test.go index 26528d24..075bd4a8 100644 --- a/src/restic/checker/checker_test.go +++ b/src/restic/checker/checker_test.go @@ -1,6 +1,7 @@ package checker_test import ( + "io" "math/rand" "path/filepath" "sort" @@ -217,6 +218,35 @@ func (b errorBackend) Load(h restic.Handle, p []byte, off int64) (int, error) { return n, err } +func (b errorBackend) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, error) { + rd, err := b.Backend.Get(h, length, offset) + if err != nil { + return rd, err + } + + if b.ProduceErrors { + return errorReadCloser{rd}, err + } + + return rd, nil +} + +type errorReadCloser struct { + io.ReadCloser +} + +func (erd errorReadCloser) Read(p []byte) (int, error) { + n, err := erd.ReadCloser.Read(p) + if n > 0 { + induceError(p[:n]) + } + return n, err +} + +func (erd errorReadCloser) Close() error { + return erd.ReadCloser.Close() +} + // induceError flips a bit in the slice. func induceError(data []byte) { if rand.Float32() < 0.2 { @@ -266,7 +296,7 @@ func TestCheckerModifiedData(t *testing.T) { } for _, err := range checkData(chkr) { - t.Logf("struct error: %v", err) + t.Logf("data error: %v", err) errFound = true }