mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 16:47:27 -04:00
all: use t.TempDir in tests
This removes all usage of ioutil.TempDir in tests (and a few cases of os.TempDir as well, while we're at it), which simplifies test cleanup a lot. Compile tested (go test -c) for most platforms (except zos). Change-Id: I9178f5ec615c0a6cfef36e8de78c6b72e055b7cb Reviewed-on: https://go-review.googlesource.com/c/sys/+/526297 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
committed by
Gopher Robot
parent
0514fecd90
commit
0e97d69659
+4
-13
@@ -11,7 +11,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
@@ -29,16 +28,12 @@ func TestDirent(t *testing.T) {
|
||||
filenameMinSize = 11
|
||||
)
|
||||
|
||||
d, err := ioutil.TempDir("", "dirent-test")
|
||||
if err != nil {
|
||||
t.Fatalf("tempdir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(d)
|
||||
d := t.TempDir()
|
||||
t.Logf("tmpdir: %s", d)
|
||||
|
||||
for i, c := range []byte("0123456789") {
|
||||
name := string(bytes.Repeat([]byte{c}, filenameMinSize+i))
|
||||
err = ioutil.WriteFile(filepath.Join(d, name), nil, 0644)
|
||||
err := ioutil.WriteFile(filepath.Join(d, name), nil, 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("writefile: %v", err)
|
||||
}
|
||||
@@ -98,18 +93,14 @@ func TestDirentRepeat(t *testing.T) {
|
||||
}
|
||||
|
||||
// Make a directory containing N files
|
||||
d, err := ioutil.TempDir("", "direntRepeat-test")
|
||||
if err != nil {
|
||||
t.Fatalf("tempdir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(d)
|
||||
d := t.TempDir()
|
||||
|
||||
var files []string
|
||||
for i := 0; i < N; i++ {
|
||||
files = append(files, fmt.Sprintf("file%d", i))
|
||||
}
|
||||
for _, file := range files {
|
||||
err = ioutil.WriteFile(filepath.Join(d, file), []byte("contents"), 0644)
|
||||
err := ioutil.WriteFile(filepath.Join(d, file), []byte("contents"), 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("writefile: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user