1
0
mirror of https://github.com/golang/go synced 2024-11-26 04:58:00 -07:00

syscall: replace os.MkdirTemp with T.TempDir

Updates #45402

Change-Id: I573133d6b987e8ac23e3e2018652612af684c755
Reviewed-on: https://go-review.googlesource.com/c/go/+/307990
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
This commit is contained in:
ianwoolf 2021-04-07 22:32:56 +08:00 committed by Ian Lance Taylor
parent fca51ba24a
commit f60aa7a18c
4 changed files with 8 additions and 32 deletions

View File

@ -27,16 +27,12 @@ func TestDirent(t *testing.T) {
filenameMinSize = 11
)
d, err := os.MkdirTemp("", "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 = os.WriteFile(filepath.Join(d, name), nil, 0644)
err := os.WriteFile(filepath.Join(d, name), nil, 0644)
if err != nil {
t.Fatalf("writefile: %v", err)
}
@ -93,18 +89,14 @@ func TestDirentRepeat(t *testing.T) {
}
// Make a directory containing N files
d, err := os.MkdirTemp("", "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 = os.WriteFile(filepath.Join(d, file), []byte("contents"), 0644)
err := os.WriteFile(filepath.Join(d, file), []byte("contents"), 0644)
if err != nil {
t.Fatalf("writefile: %v", err)
}

View File

@ -29,11 +29,7 @@ func testGetdirentries(t *testing.T, count int) {
if count > 100 && testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" {
t.Skip("skipping in -short mode")
}
d, err := os.MkdirTemp("", "getdirentries-test")
if err != nil {
t.Fatalf("Tempdir: %v", err)
}
defer os.RemoveAll(d)
d := t.TempDir()
var names []string
for i := 0; i < count; i++ {
names = append(names, fmt.Sprintf("file%03d", i))

View File

@ -79,16 +79,12 @@ func TestFcntlFlock(t *testing.T) {
}
if os.Getenv("GO_WANT_HELPER_PROCESS") == "" {
// parent
tempDir, err := os.MkdirTemp("", "TestFcntlFlock")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
tempDir := t.TempDir()
name := filepath.Join(tempDir, "TestFcntlFlock")
fd, err := syscall.Open(name, syscall.O_CREAT|syscall.O_RDWR|syscall.O_CLOEXEC, 0)
if err != nil {
t.Fatalf("Open failed: %v", err)
}
defer os.RemoveAll(tempDir)
defer syscall.Close(fd)
if err := syscall.Ftruncate(fd, 1<<20); err != nil {
t.Fatalf("Ftruncate(1<<20) failed: %v", err)
@ -157,11 +153,7 @@ func TestPassFD(t *testing.T) {
}
tempDir, err := os.MkdirTemp("", "TestPassFD")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()
fds, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM, 0)
if err != nil {

View File

@ -12,11 +12,7 @@ import (
)
func TestWin32finddata(t *testing.T) {
dir, err := os.MkdirTemp("", "go-build")
if err != nil {
t.Fatalf("failed to create temp directory: %v", err)
}
defer os.RemoveAll(dir)
dir := t.TempDir()
path := filepath.Join(dir, "long_name.and_extension")
f, err := os.Create(path)