diff options
author | Félix Sipma <felix+debian@gueux.org> | 2022-05-11 20:44:31 +0200 |
---|---|---|
committer | Félix Sipma <felix+debian@gueux.org> | 2022-05-11 20:44:31 +0200 |
commit | ec2b7560950878d653cd49f0658a126a0fcb2e4f (patch) | |
tree | 519ad710a8daa6a31c06e6ed00b2eb3d5690cfdb /internal/restorer/restorer_test.go | |
parent | 46221fa4705de029b2f697286c3ca5d67ae20d39 (diff) |
New upstream version 0.13.1
Diffstat (limited to 'internal/restorer/restorer_test.go')
-rw-r--r-- | internal/restorer/restorer_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/restorer/restorer_test.go b/internal/restorer/restorer_test.go index 32be0f51d..a5a3bb5ba 100644 --- a/internal/restorer/restorer_test.go +++ b/internal/restorer/restorer_test.go @@ -367,6 +367,11 @@ func TestRestorer(t *testing.T) { t.Fatal(err) } + if len(test.ErrorsMust)+len(test.ErrorsMay) == 0 { + _, err = res.VerifyFiles(ctx, tempdir) + rtest.OK(t, err) + } + for location, expectedErrors := range test.ErrorsMust { actualErrors, ok := errors[location] if !ok { @@ -465,6 +470,9 @@ func TestRestorerRelative(t *testing.T) { if err != nil { t.Fatal(err) } + nverified, err := res.VerifyFiles(ctx, "restore") + rtest.OK(t, err) + rtest.Equals(t, len(test.Files), nverified) for filename, err := range errors { t.Errorf("unexpected error for %v found: %v", filename, err) @@ -800,3 +808,42 @@ func TestRestorerConsistentTimestampsAndPermissions(t *testing.T) { checkConsistentInfo(t, test.path, f, test.modtime, test.mode) } } + +// VerifyFiles must not report cancelation of its context through res.Error. +func TestVerifyCancel(t *testing.T) { + snapshot := Snapshot{ + Nodes: map[string]Node{ + "foo": File{Data: "content: foo\n"}, + }, + } + + repo, cleanup := repository.TestRepository(t) + defer cleanup() + + _, id := saveSnapshot(t, repo, snapshot) + + res, err := NewRestorer(context.TODO(), repo, id) + rtest.OK(t, err) + + tempdir, cleanup := rtest.TempDir(t) + defer cleanup() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + rtest.OK(t, res.RestoreTo(ctx, tempdir)) + err = ioutil.WriteFile(filepath.Join(tempdir, "foo"), []byte("bar"), 0644) + rtest.OK(t, err) + + var errs []error + res.Error = func(filename string, err error) error { + errs = append(errs, err) + return err + } + + nverified, err := res.VerifyFiles(ctx, tempdir) + rtest.Equals(t, 0, nverified) + rtest.Assert(t, err != nil, "nil error from VerifyFiles") + rtest.Equals(t, 1, len(errs)) + rtest.Assert(t, strings.Contains(errs[0].Error(), "Invalid file size for"), "wrong error %q", errs[0].Error()) +} |