Fix checker test

This commit is contained in:
Alexander Neumann 2017-01-23 16:07:58 +01:00
parent 212936eb52
commit 4a354befe5

View file

@ -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
}