diff --git a/internal/archiver/archiver_test.go b/internal/archiver/archiver_test.go index 906c83011..9cbce7c76 100644 --- a/internal/archiver/archiver_test.go +++ b/internal/archiver/archiver_test.go @@ -1870,12 +1870,13 @@ func TestArchiverErrorReporting(t *testing.T) { } var tests = []struct { - name string - src TestDir - want TestDir - prepare func(t testing.TB) - errFn ErrorFunc - mustError bool + name string + targets []string + src TestDir + want TestDir + prepare func(t testing.TB) + errFn ErrorFunc + errStr string }{ { name: "no-error", @@ -1888,8 +1889,8 @@ func TestArchiverErrorReporting(t *testing.T) { src: TestDir{ "targetfile": TestFile{Content: "foobar"}, }, - prepare: chmodUnreadable("targetfile"), - mustError: true, + prepare: chmodUnreadable("targetfile"), + errStr: "open targetfile: permission denied", }, { name: "file-unreadable-ignore-error", @@ -1910,8 +1911,8 @@ func TestArchiverErrorReporting(t *testing.T) { "targetfile": TestFile{Content: "foobar"}, }, }, - prepare: chmodUnreadable("subdir/targetfile"), - mustError: true, + prepare: chmodUnreadable("subdir/targetfile"), + errStr: "open subdir/targetfile: permission denied", }, { name: "file-subdir-unreadable-ignore-error", @@ -1929,6 +1930,12 @@ func TestArchiverErrorReporting(t *testing.T) { prepare: chmodUnreadable("subdir/targetfile"), errFn: ignoreErrorForBasename("targetfile"), }, + { + name: "parent-dir-missing", + targets: []string{"subdir/missing"}, + src: TestDir{}, + errStr: "stat subdir: no such file or directory", + }, } for _, test := range tests { @@ -1948,14 +1955,18 @@ func TestArchiverErrorReporting(t *testing.T) { arch := New(repo, fs.Track{FS: fs.Local{}}, Options{}) arch.Error = test.errFn - _, snapshotID, _, err := arch.Snapshot(ctx, []string{"."}, SnapshotOptions{Time: time.Now()}) - if test.mustError { - if err != nil { + target := test.targets + if len(target) == 0 { + target = []string{"."} + } + _, snapshotID, _, err := arch.Snapshot(ctx, target, SnapshotOptions{Time: time.Now()}) + if test.errStr != "" { + if strings.Contains(err.Error(), test.errStr) { t.Logf("found expected error (%v), skipping further checks", err) return } - t.Fatalf("expected error not returned by archiver") + t.Fatalf("expected error (%v) not returned by archiver, got (%v)", test.errStr, err) return }