From ea41a1045f6acbfb1396facc3f7e9d27037eaab7 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 6 Nov 2015 23:19:56 +0100 Subject: [PATCH] Add integration test for error on readdirnames --- cmd/restic/integration_test.go | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index fa95eca92..9880ea164 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -291,6 +291,56 @@ func TestBackupMissingFile2(t *testing.T) { }) } +func TestBackupDirectoryError(t *testing.T) { + withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) { + datafile := filepath.Join("testdata", "backup-data.tar.gz") + fd, err := os.Open(datafile) + if os.IsNotExist(err) { + t.Skipf("unable to find data file %q, skipping", datafile) + return + } + OK(t, err) + OK(t, fd.Close()) + + SetupTarTestFixture(t, env.testdata, datafile) + + cmdInit(t, global) + + global.stderr = ioutil.Discard + ranHook := false + + testdir := filepath.Join(env.testdata, "0", "0", "9") + + // install hook that removes the dir right before readdirnames() + debug.Hook("pipe.readdirnames", func(context interface{}) { + path := context.(string) + + if path != testdir { + return + } + + t.Logf("in hook, removing test file %v", testdir) + ranHook = true + + OK(t, os.RemoveAll(testdir)) + }) + + cmdBackup(t, global, []string{filepath.Join(env.testdata, "0", "0")}, nil) + cmdCheck(t, global) + + Assert(t, ranHook, "hook did not run") + debug.RemoveHook("pipe.walk2") + + snapshots := cmdList(t, global, "snapshots") + Assert(t, len(snapshots) > 0, + "no snapshots found in repo (%v)", datafile) + + files := cmdLs(t, global, snapshots[0].String()) + + Assert(t, len(files) > 1, "snapshot is empty") + }) +} + func includes(haystack []string, needle string) bool { for _, s := range haystack { if s == needle {