pipe: make test platform-independent

This commit is contained in:
Alexander Neumann 2015-11-06 22:38:34 +01:00
parent 1569176e48
commit 005c13ff05
2 changed files with 19 additions and 5 deletions

View file

@ -113,6 +113,7 @@ func walk(basedir, dir string, selectFunc SelectFunc, done <-chan struct{}, jobs
return return
} }
debug.RunHook("pipe.readdirnames", dir)
names, err := readDirNames(dir) names, err := readDirNames(dir)
if err != nil { if err != nil {
debug.Log("pipe.walk", "Readdirnames(%v) returned error: %v", dir, err) debug.Log("pipe.walk", "Readdirnames(%v) returned error: %v", dir, err)

View file

@ -1,7 +1,6 @@
package pipe_test package pipe_test
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -9,6 +8,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/restic/restic/debug"
"github.com/restic/restic/pipe" "github.com/restic/restic/pipe"
. "github.com/restic/restic/test" . "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, "b", "file_b"), "file b"))
OK(t, createFile(filepath.Join(dir, "c", "file_c"), "file c")) 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{}) done := make(chan struct{})
ch := make(chan pipe.Job) ch := make(chan pipe.Job)
@ -275,8 +290,6 @@ func TestPipeWalkerError(t *testing.T) {
break break
} }
fmt.Printf("job %+v: %+v\n", job.Path(), job)
p := filepath.Join(testjobs[i].path...) p := filepath.Join(testjobs[i].path...)
if p != job.Path() { if p != job.Path() {
t.Errorf("job %d has wrong path: expected %q, got %q", i, 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) close(done)
OK(t, os.Chmod(filepath.Join(dir, "b"), 0755)) Assert(t, ranHook, "hook did not run")
OK(t, os.RemoveAll(dir)) OK(t, os.RemoveAll(dir))
} }