From 005c13ff05ecd7be82d8c86c4c555e5b8e6f9429 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 6 Nov 2015 22:38:34 +0100 Subject: [PATCH] pipe: make test platform-independent --- pipe/pipe.go | 1 + pipe/pipe_test.go | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pipe/pipe.go b/pipe/pipe.go index d911f6087..1599efa19 100644 --- a/pipe/pipe.go +++ b/pipe/pipe.go @@ -113,6 +113,7 @@ func walk(basedir, dir string, selectFunc SelectFunc, done <-chan struct{}, jobs return } + debug.RunHook("pipe.readdirnames", dir) names, err := readDirNames(dir) if err != nil { debug.Log("pipe.walk", "Readdirnames(%v) returned error: %v", dir, err) diff --git a/pipe/pipe_test.go b/pipe/pipe_test.go index 95bbf7db8..40ae8c0ce 100644 --- a/pipe/pipe_test.go +++ b/pipe/pipe_test.go @@ -1,7 +1,6 @@ package pipe_test import ( - "fmt" "io/ioutil" "os" "path/filepath" @@ -9,6 +8,7 @@ import ( "testing" "time" + "github.com/restic/restic/debug" "github.com/restic/restic/pipe" . "github.com/restic/restic/test" ) @@ -260,7 +260,22 @@ func TestPipeWalkerError(t *testing.T) { OK(t, createFile(filepath.Join(dir, "b", "file_b"), "file b")) OK(t, createFile(filepath.Join(dir, "c", "file_c"), "file c")) - OK(t, os.Chmod(filepath.Join(dir, "b"), 0)) + ranHook := false + testdir := filepath.Join(dir, "b") + + // 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)) + }) done := make(chan struct{}) ch := make(chan pipe.Job) @@ -275,8 +290,6 @@ func TestPipeWalkerError(t *testing.T) { break } - fmt.Printf("job %+v: %+v\n", job.Path(), job) - p := filepath.Join(testjobs[i].path...) if p != job.Path() { t.Errorf("job %d has wrong path: expected %q, got %q", i, p, job.Path()) @@ -301,7 +314,7 @@ func TestPipeWalkerError(t *testing.T) { close(done) - OK(t, os.Chmod(filepath.Join(dir, "b"), 0755)) + Assert(t, ranHook, "hook did not run") OK(t, os.RemoveAll(dir)) }