mirror of
https://github.com/restic/restic.git
synced 2025-02-03 04:56:48 +00:00
Fix checker test
This commit is contained in:
parent
212936eb52
commit
4a354befe5
1 changed files with 31 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
package checker_test
|
package checker_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -217,6 +218,35 @@ func (b errorBackend) Load(h restic.Handle, p []byte, off int64) (int, error) {
|
||||||
return n, err
|
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.
|
// induceError flips a bit in the slice.
|
||||||
func induceError(data []byte) {
|
func induceError(data []byte) {
|
||||||
if rand.Float32() < 0.2 {
|
if rand.Float32() < 0.2 {
|
||||||
|
@ -266,7 +296,7 @@ func TestCheckerModifiedData(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, err := range checkData(chkr) {
|
for _, err := range checkData(chkr) {
|
||||||
t.Logf("struct error: %v", err)
|
t.Logf("data error: %v", err)
|
||||||
errFound = true
|
errFound = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue