mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:47:50 +00:00
backup: test that missing parent directory is correctly handled
This commit is contained in:
@@ -1871,11 +1871,12 @@ func TestArchiverErrorReporting(t *testing.T) {
|
|||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
name string
|
name string
|
||||||
|
targets []string
|
||||||
src TestDir
|
src TestDir
|
||||||
want TestDir
|
want TestDir
|
||||||
prepare func(t testing.TB)
|
prepare func(t testing.TB)
|
||||||
errFn ErrorFunc
|
errFn ErrorFunc
|
||||||
mustError bool
|
errStr string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no-error",
|
name: "no-error",
|
||||||
@@ -1889,7 +1890,7 @@ func TestArchiverErrorReporting(t *testing.T) {
|
|||||||
"targetfile": TestFile{Content: "foobar"},
|
"targetfile": TestFile{Content: "foobar"},
|
||||||
},
|
},
|
||||||
prepare: chmodUnreadable("targetfile"),
|
prepare: chmodUnreadable("targetfile"),
|
||||||
mustError: true,
|
errStr: "open targetfile: permission denied",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "file-unreadable-ignore-error",
|
name: "file-unreadable-ignore-error",
|
||||||
@@ -1911,7 +1912,7 @@ func TestArchiverErrorReporting(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
prepare: chmodUnreadable("subdir/targetfile"),
|
prepare: chmodUnreadable("subdir/targetfile"),
|
||||||
mustError: true,
|
errStr: "open subdir/targetfile: permission denied",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "file-subdir-unreadable-ignore-error",
|
name: "file-subdir-unreadable-ignore-error",
|
||||||
@@ -1929,6 +1930,12 @@ func TestArchiverErrorReporting(t *testing.T) {
|
|||||||
prepare: chmodUnreadable("subdir/targetfile"),
|
prepare: chmodUnreadable("subdir/targetfile"),
|
||||||
errFn: ignoreErrorForBasename("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 {
|
for _, test := range tests {
|
||||||
@@ -1948,14 +1955,18 @@ func TestArchiverErrorReporting(t *testing.T) {
|
|||||||
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
|
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
|
||||||
arch.Error = test.errFn
|
arch.Error = test.errFn
|
||||||
|
|
||||||
_, snapshotID, _, err := arch.Snapshot(ctx, []string{"."}, SnapshotOptions{Time: time.Now()})
|
target := test.targets
|
||||||
if test.mustError {
|
if len(target) == 0 {
|
||||||
if err != nil {
|
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)
|
t.Logf("found expected error (%v), skipping further checks", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Fatalf("expected error not returned by archiver")
|
t.Fatalf("expected error (%v) not returned by archiver, got (%v)", test.errStr, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user