diff options
author | Mostyn Bramley-Moore <mostyn@antipode.se> | 2018-03-05 22:04:47 +0000 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-03-05 23:38:39 +0000 |
commit | 32e459a09cd2da967fc2c0accf197fecc7b658d5 (patch) | |
tree | 353b594fddfe4e006c5c3c664054e8424d6ce8f3 /src/path | |
parent | 26708439ecb4dc923149b17eb522df46dcc2fb23 (diff) | |
download | go-32e459a09cd2da967fc2c0accf197fecc7b658d5.tar.gz go-32e459a09cd2da967fc2c0accf197fecc7b658d5.zip |
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: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/path')
-rw-r--r-- | src/path/filepath/path_test.go | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index 3ebd3fbd2d..6e8d1cb432 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -433,6 +433,22 @@ func TestWalk(t *testing.T) { 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) errors := make([]error, 0, 10) clear := true @@ -440,7 +456,7 @@ func TestWalk(t *testing.T) { return mark(info, err, &errors, clear) } // Expect no errors. - err := filepath.Walk(tree.name, markFn) + err = filepath.Walk(tree.name, markFn) if err != nil { t.Fatalf("no error expected, found: %s", err) } @@ -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[3].name), 0770) } - - // cleanup - if err := os.RemoveAll(tree.name); err != nil { - t.Errorf("removeTree: %v", err) - } } func touch(t *testing.T, name string) { |