net/http: replace os.MkdirTemp with T.TempDir

Updates: #45402
Change-Id: Ia61f422d058bf57fc3688abc25597d6cc1692c51
Reviewed-on: https://go-review.googlesource.com/c/go/+/307653
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
This commit is contained in:
ianwoolf 2021-04-07 13:42:22 +08:00 committed by Emmanuel Odeke
parent 4bbe046aad
commit 5d5f779db4
2 changed files with 3 additions and 9 deletions

View file

@ -23,12 +23,10 @@ func checker(t *testing.T) func(string, error) {
func TestFileTransport(t *testing.T) {
check := checker(t)
dname, err := os.MkdirTemp("", "")
check("TempDir", err)
dname := t.TempDir()
fname := filepath.Join(dname, "foo.txt")
err = os.WriteFile(fname, []byte("Bar"), 0644)
err := os.WriteFile(fname, []byte("Bar"), 0644)
check("WriteFile", err)
defer os.Remove(dname)
defer os.Remove(fname)
tr := &Transport{}

View file

@ -378,11 +378,7 @@ func mustRemoveAll(dir string) {
func TestFileServerImplicitLeadingSlash(t *testing.T) {
defer afterTest(t)
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("TempDir: %v", err)
}
defer mustRemoveAll(tempDir)
tempDir := t.TempDir()
if err := os.WriteFile(filepath.Join(tempDir, "foo.txt"), []byte("Hello world"), 0644); err != nil {
t.Fatalf("WriteFile: %v", err)
}