mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-29 13:26:45 -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
@@ -688,11 +688,10 @@ func TestFaccessat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSyncFileRange(t *testing.T) {
|
||||
file, err := ioutil.TempFile("", "TestSyncFileRange")
|
||||
file, err := os.Create(filepath.Join(t.TempDir(), t.Name()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
defer file.Close()
|
||||
|
||||
err = unix.SyncFileRange(int(file.Fd()), 0, 0, 0)
|
||||
@@ -1024,12 +1023,12 @@ func TestOpenat2(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIoctlFileDedupeRange(t *testing.T) {
|
||||
f1, err := ioutil.TempFile("", t.Name())
|
||||
dir := t.TempDir()
|
||||
f1, err := os.Create(filepath.Join(dir, "f1"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f1.Close()
|
||||
defer os.Remove(f1.Name())
|
||||
|
||||
// Test deduplication with two blocks of zeros
|
||||
data := make([]byte, 4096)
|
||||
@@ -1041,12 +1040,11 @@ func TestIoctlFileDedupeRange(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
f2, err := ioutil.TempFile("", t.Name())
|
||||
f2, err := os.Create(filepath.Join(dir, "f2"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f2.Close()
|
||||
defer os.Remove(f2.Name())
|
||||
|
||||
for i := 0; i < 2; i += 1 {
|
||||
// Make the 2nd block different
|
||||
|
||||
Reference in New Issue
Block a user