mirror of
https://github.com/restic/restic.git
synced 2025-10-19 15:43:21 +00:00
backup: test that missing parent directory is correctly handled
This commit is contained in:
parent
fc81df3f54
commit
d57b01d6eb
1 changed files with 25 additions and 14 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue