Add failing test for fileRestorer

This commit is contained in:
Alexander Weiss 2021-01-01 09:50:47 +01:00
parent f647614e24
commit 573221aa40
1 changed files with 27 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"testing"
"github.com/restic/restic/internal/crypto"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/restic"
rtest "github.com/restic/restic/internal/test"
)
@ -237,3 +238,29 @@ func TestFileRestorerPackSkip(t *testing.T) {
},
}, files)
}
func TestErrorRestoreFiles(t *testing.T) {
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
content := []TestFile{
{
name: "file1",
blobs: []TestBlob{
{"data1-1", "pack1-1"},
},
}}
repo := newTestRepo(content)
loadError := errors.New("load error")
// loader always returns an error
repo.loader = func(ctx context.Context, h restic.Handle, length int, offset int64, fn func(rd io.Reader) error) error {
return loadError
}
r := newFileRestorer(tempdir, repo.loader, repo.key, repo.Lookup)
r.files = repo.files
err := r.restoreFiles(context.TODO())
rtest.Assert(t, err != nil, "restoreFiles should have reported an error!")
}