From 573221aa4077f9a889f0dbcf17e43fbf8994d87d Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Fri, 1 Jan 2021 09:50:47 +0100 Subject: [PATCH] Add failing test for fileRestorer --- internal/restorer/filerestorer_test.go | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/internal/restorer/filerestorer_test.go b/internal/restorer/filerestorer_test.go index 28bcd5e28..6ccbc2b37 100644 --- a/internal/restorer/filerestorer_test.go +++ b/internal/restorer/filerestorer_test.go @@ -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!") +}