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>
diff --git a/src/net/http/filetransport_test.go b/src/net/http/filetransport_test.go
index b58888d..77fc8ee 100644
--- a/src/net/http/filetransport_test.go
+++ b/src/net/http/filetransport_test.go
@@ -23,12 +23,10 @@
 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{}
diff --git a/src/net/http/fs_test.go b/src/net/http/fs_test.go
index 0ebb511..1bf207e 100644
--- a/src/net/http/fs_test.go
+++ b/src/net/http/fs_test.go
@@ -378,11 +378,7 @@
 
 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)
 	}