1
0
mirror of https://github.com/golang/go synced 2024-11-19 05:04:43 -07:00

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 <iant@golang.org>
This commit is contained in:
Mostyn Bramley-Moore 2017-04-17 04:16:55 +02:00 committed by Ian Lance Taylor
parent eed6938cbb
commit 273f449783

View File

@ -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()