Commit 32e459a0 authored by Mostyn Bramley-Moore's avatar Mostyn Bramley-Moore Committed by Brad Fitzpatrick

path/filepath: use a temp dir in path_test.go

We should avoid writing temp files to GOROOT, since it might be readonly.

Fixes #23881

Change-Id: Iaa38ec404b303f0cf27fdfb7daf1ddd60fd5d1c9
GitHub-Last-Rev: de0211df8474cc3bbef40f792e2f85b3b6ee259c
GitHub-Pull-Request: golang/go#24238
Reviewed-on: https://go-review.googlesource.com/98517
Run-TryBot: Giovanni Bajo <rasky@develer.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 26708439
...@@ -433,6 +433,22 @@ func TestWalk(t *testing.T) { ...@@ -433,6 +433,22 @@ func TestWalk(t *testing.T) {
defer restore() defer restore()
} }
} }
tmpDir, err := ioutil.TempDir("", "TestWalk")
if err != nil {
t.Fatal("creating temp dir:", err)
}
defer os.RemoveAll(tmpDir)
origDir, err := os.Getwd()
if err != nil {
t.Fatal("finding working dir:", err)
}
if err = os.Chdir(tmpDir); err != nil {
t.Fatal("entering temp dir:", err)
}
defer os.Chdir(origDir)
makeTree(t) makeTree(t)
errors := make([]error, 0, 10) errors := make([]error, 0, 10)
clear := true clear := true
...@@ -440,7 +456,7 @@ func TestWalk(t *testing.T) { ...@@ -440,7 +456,7 @@ func TestWalk(t *testing.T) {
return mark(info, err, &errors, clear) return mark(info, err, &errors, clear)
} }
// Expect no errors. // Expect no errors.
err := filepath.Walk(tree.name, markFn) err = filepath.Walk(tree.name, markFn)
if err != nil { if err != nil {
t.Fatalf("no error expected, found: %s", err) t.Fatalf("no error expected, found: %s", err)
} }
...@@ -499,11 +515,6 @@ func TestWalk(t *testing.T) { ...@@ -499,11 +515,6 @@ func TestWalk(t *testing.T) {
os.Chmod(filepath.Join(tree.name, tree.entries[1].name), 0770) os.Chmod(filepath.Join(tree.name, tree.entries[1].name), 0770)
os.Chmod(filepath.Join(tree.name, tree.entries[3].name), 0770) os.Chmod(filepath.Join(tree.name, tree.entries[3].name), 0770)
} }
// cleanup
if err := os.RemoveAll(tree.name); err != nil {
t.Errorf("removeTree: %v", err)
}
} }
func touch(t *testing.T, name string) { func touch(t *testing.T, name string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment