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:
Kir Kolyshkin
2023-09-12 16:41:25 +00:00
committed by Gopher Robot
parent cb4ecd9fe9
commit fc717d344a
7 changed files with 47 additions and 73 deletions
+2 -3
View File
@@ -8,8 +8,8 @@
package unix_test
import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
@@ -127,11 +127,10 @@ func TestXattr(t *testing.T) {
}
func TestFdXattr(t *testing.T) {
file, err := ioutil.TempFile("", "TestFdXattr")
file, err := os.Create(filepath.Join(t.TempDir(), "TestFdXattr"))
if err != nil {
t.Fatal(err)
}
defer os.Remove(file.Name())
defer file.Close()
fd := int(file.Fd())