mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 07:07:33 -04:00
unix: remove usage of ioutil.TempFile in tests
Mostly change that to os.Create(filepath.Join(t.TempDir(), "filename")) so that the cleanup is done automatically (and, because this is a new directory, we do not need to have a "create unique temp file name" logic). While at it, fix some log/error messages -- if an error is coming from e.g. os package, it is already wrapped, so there's no need to add more context. Change-Id: I62f13679f256b94095be5ca1e77a3fa302f01b97 Reviewed-on: https://go-review.googlesource.com/c/sys/+/526298 Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
committed by
Gopher Robot
parent
cb4ecd9fe9
commit
fc717d344a
@@ -126,11 +126,10 @@ func TestSignalNum(t *testing.T) {
|
||||
|
||||
func TestFcntlInt(t *testing.T) {
|
||||
t.Parallel()
|
||||
file, err := ioutil.TempFile("", "TestFcntlInt")
|
||||
file, err := os.Create(filepath.Join(t.TempDir(), t.Name()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
defer file.Close()
|
||||
f := file.Fd()
|
||||
flags, err := unix.FcntlInt(f, unix.F_GETFD, 0)
|
||||
@@ -293,9 +292,9 @@ func passFDChild() {
|
||||
// We make it in tempDir, which our parent will clean up.
|
||||
flag.Parse()
|
||||
tempDir := flag.Arg(0)
|
||||
f, err := ioutil.TempFile(tempDir, "")
|
||||
f, err := os.Create(filepath.Join(tempDir, "file"))
|
||||
if err != nil {
|
||||
fmt.Printf("TempFile: %v", err)
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -452,11 +451,10 @@ func TestSetsockoptString(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDup(t *testing.T) {
|
||||
file, err := ioutil.TempFile("", "TestDup")
|
||||
file, err := os.Create(filepath.Join(t.TempDir(), t.Name()))
|
||||
if err != nil {
|
||||
t.Fatalf("Tempfile failed: %v", err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
defer file.Close()
|
||||
f := int(file.Fd())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user