From 273f4497833add6bec4a0b550caf23c0b3d9b0ec Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Mon, 17 Apr 2017 04:16:55 +0200 Subject: [PATCH] cmd/go/internal/work: clean up after TestRespectGroupSticky Use our own tempdir, to avoid having to Init (and somehow teardown) Builder. This way we don't leave behind any temp files. Also, don't create a hardcoded path inside a testcase. Followup to golang/go#18878. Fixes golang/go#19449. Change-Id: Ieb1ebeab24ae8a74a6fa058d9c23f72b3fc1c444 Reviewed-on: https://go-review.googlesource.com/40912 Reviewed-by: Ian Lance Taylor --- src/cmd/go/internal/work/build_test.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/cmd/go/internal/work/build_test.go b/src/cmd/go/internal/work/build_test.go index 2bfb6cb8145..3f811ddc820 100644 --- a/src/cmd/go/internal/work/build_test.go +++ b/src/cmd/go/internal/work/build_test.go @@ -9,7 +9,6 @@ import ( "fmt" "io/ioutil" "os" - "path" "path/filepath" "reflect" "runtime" @@ -181,7 +180,6 @@ func TestRespectGroupSticky(t *testing.T) { } var b Builder - b.Init() // Check that `cp` is called instead of `mv` by looking at the output // of `(*Builder).ShowCmd` afterwards as a sanity check. @@ -191,21 +189,20 @@ func TestRespectGroupSticky(t *testing.T) { return cmdBuf.WriteString(fmt.Sprint(a...)) } - stickydir := path.Join(os.TempDir(), "GroupSticky") - if err := os.Mkdir(stickydir, 0755); err != nil { + stickydir, err := ioutil.TempDir("", "GroupSticky") + if err != nil { t.Fatal(err) } defer os.RemoveAll(stickydir) - // Mkdir doesn't always correctly set the group sticky bit. // Change stickydir's permissions to include group sticky bit. if err := os.Chmod(stickydir, 0755|os.ModeSetgid); err != nil { t.Fatal(err) } - pkgfile, err := ioutil.TempFile(b.WorkDir, "") + pkgfile, err := ioutil.TempFile("", "pkgfile") if err != nil { - t.Fatalf("ioutil.TempFile(%q): %v", b.WorkDir, err) + t.Fatalf("ioutil.TempFile(\"\", \"pkgfile\"): %v", err) } defer os.Remove(pkgfile.Name()) defer pkgfile.Close()