[infra] Remove most calls to testutils.TempDir()

t.TempDir() from go 1.15 is easier to use.

Change-Id: I3c7ea6303e30a84d77039ca3c6066de0f2833499
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/372497
Reviewed-by: Eric Boren <borenet@google.com>
diff --git a/autoroll/go/repo_manager/child/cipd_manual_test.go b/autoroll/go/repo_manager/child/cipd_manual_test.go
index 7dc2d36..27dc198 100644
--- a/autoroll/go/repo_manager/child/cipd_manual_test.go
+++ b/autoroll/go/repo_manager/child/cipd_manual_test.go
@@ -10,7 +10,6 @@
 	"go.skia.org/infra/autoroll/go/revision"
 	"go.skia.org/infra/go/auth"
 	"go.skia.org/infra/go/httputils"
-	"go.skia.org/infra/go/testutils"
 	"go.skia.org/infra/go/testutils/unittest"
 	"go.skia.org/infra/go/vfs"
 )
@@ -40,9 +39,7 @@
 	ts, err := auth.NewDefaultTokenSource(true, auth.SCOPE_USERINFO_EMAIL)
 	require.NoError(t, err)
 	client := httputils.DefaultClientConfig().WithTokenSource(ts).With2xxOnly().Client()
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
-
+	wd := t.TempDir()
 	c, err := NewCIPD(ctx, &cfg, client, wd)
 	require.NoError(t, err)
 
diff --git a/go/config/config_test.go b/go/config/config_test.go
index 3ad579a..d71e3f3 100644
--- a/go/config/config_test.go
+++ b/go/config/config_test.go
@@ -86,8 +86,7 @@
 
 func TestParseConfigFileDoesntExist(t *testing.T) {
 	unittest.MediumTest(t)
-	dir, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	dir := t.TempDir()
 	configFile := filepath.Join(dir, "nonexistent-file.json5")
 	parsed := TestConfig{}
 	err := ParseConfigFile(configFile, "--main-config", &parsed)
@@ -97,8 +96,7 @@
 
 func TestParseConfigFileInvalid(t *testing.T) {
 	unittest.MediumTest(t)
-	dir, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	dir := t.TempDir()
 	configFile := filepath.Join(dir, "invalid.json5")
 	require.NoError(t, ioutil.WriteFile(configFile, []byte("Hi Mom!"), os.ModePerm))
 	parsed := TestConfig{}
diff --git a/go/testutils/testutils.go b/go/testutils/testutils.go
index 65279f2..564b1fe 100644
--- a/go/testutils/testutils.go
+++ b/go/testutils/testutils.go
@@ -12,9 +12,7 @@
 	"os"
 	"path/filepath"
 	"runtime"
-	"strings"
 	"sync"
-	"testing"
 	"text/template"
 	"time"
 
@@ -139,13 +137,7 @@
 	return string(b)
 }
 
-// AssertErrorContains asserts that the given error contains the given string.
-func AssertErrorContains(t sktest.TestingT, err error, substr string) {
-	require.NotNil(t, err)
-	require.True(t, strings.Contains(err.Error(), substr))
-}
-
-// Return the path to the root of the checkout.
+// GetRepoRoot returns the path to the root of the checkout.
 func GetRepoRoot(t sktest.TestingT) string {
 	root, err := repo_root.Get()
 	require.NoError(t, err)
@@ -289,7 +281,7 @@
 // which do not depend on the specifics of the $HOME directory in the host system.
 //
 // See https://docs.bazel.build/versions/master/test-encyclopedia.html#initial-conditions.
-func SetUpFakeHomeDir(t *testing.T, tempDirPattern string) {
+func SetUpFakeHomeDir(t sktest.TestingT, tempDirPattern string) {
 	fakeHome, err := ioutil.TempDir("", tempDirPattern)
 	require.NoError(t, err)
 	oldHome := os.Getenv("HOME")
diff --git a/gold-client/go/gcsuploader/gcsuploader_test.go b/gold-client/go/gcsuploader/gcsuploader_test.go
index 6979930..94205ab 100644
--- a/gold-client/go/gcsuploader/gcsuploader_test.go
+++ b/gold-client/go/gcsuploader/gcsuploader_test.go
@@ -11,7 +11,6 @@
 	"github.com/stretchr/testify/require"
 
 	"go.skia.org/infra/go/exec"
-	"go.skia.org/infra/go/testutils"
 	"go.skia.org/infra/go/testutils/unittest"
 )
 
@@ -31,8 +30,7 @@
 func TestGSutil_UploadJSON_Success(t *testing.T) {
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 	tf := filepath.Join(wd, "foo.json")
 
 	cc := exec.CommandCollector{}
diff --git a/gold-client/go/goldclient/goldclient_test.go b/gold-client/go/goldclient/goldclient_test.go
index 9c46a49..faa0888 100644
--- a/gold-client/go/goldclient/goldclient_test.go
+++ b/gold-client/go/goldclient/goldclient_test.go
@@ -41,8 +41,7 @@
 func TestLoadKnownHashes(t *testing.T) {
 	unittest.SmallTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, httpClient, uploader, _ := makeMocks()
 	defer httpClient.AssertExpectations(t)
@@ -74,8 +73,7 @@
 func TestLoadBaseline(t *testing.T) {
 	unittest.SmallTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, httpClient, uploader, _ := makeMocks()
 	defer httpClient.AssertExpectations(t)
@@ -110,8 +108,7 @@
 func TestLoadBaselineMaster(t *testing.T) {
 	unittest.SmallTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, httpClient, uploader, _ := makeMocks()
 	defer httpClient.AssertExpectations(t)
@@ -155,8 +152,7 @@
 	// This test reads and writes a small amount of data from/to disk
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, httpClient, uploader, _ := makeMocks()
 	defer httpClient.AssertExpectations(t)
@@ -198,8 +194,7 @@
 func TestInitInvalidKeys(t *testing.T) {
 	unittest.SmallTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, _, _, _ := makeMocks()
 
@@ -218,8 +213,7 @@
 	// This test reads and writes a small amount of data from/to disk
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, httpClient, uploader, _ := makeMocks()
 	defer httpClient.AssertExpectations(t)
@@ -321,8 +315,7 @@
 func TestNewReportNormal(t *testing.T) {
 	unittest.SmallTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	imgHash := types.Digest("9d0568469d206c1aedf1b71f12f474bc")
@@ -363,8 +356,7 @@
 func TestNewReportDigestAndImageSupplied(t *testing.T) {
 	unittest.SmallTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	// This is the digest the client has calculated
@@ -407,8 +399,7 @@
 func TestNewReportDigestSupplied(t *testing.T) {
 	unittest.SmallTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	// This is the digest the client has calculated
 	const precalculatedDigest = "00000000000000111111111111111222"
@@ -446,8 +437,7 @@
 func TestNewReportNormalBadKeys(t *testing.T) {
 	unittest.SmallTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	imgHash := types.Digest("9d0568469d206c1aedf1b71f12f474bc")
@@ -484,8 +474,7 @@
 	// This test reads and writes a small amount of data from/to disk
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, httpClient, uploader, _ := makeMocks()
 	defer httpClient.AssertExpectations(t)
@@ -566,8 +555,7 @@
 	// We read and write to disk a little
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	const firstHash = types.Digest("9d0568469d206c1aedf1b71f12f474bc")
@@ -665,8 +653,7 @@
 func TestNewReportPassFail(t *testing.T) {
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	imgHash := types.Digest("9d0568469d206c1aedf1b71f12f474bc")
@@ -741,8 +728,7 @@
 func TestReportPassFailPassWithCorpusInInit(t *testing.T) {
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	// These are defined in mockBaselineJSON
@@ -817,8 +803,7 @@
 func TestReportPassFailPassWithCorpusInKeys(t *testing.T) {
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	// These are defined in mockBaselineJSON
@@ -895,8 +880,7 @@
 func TestReportPassFailPassWithFuzzyMatching(t *testing.T) {
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	// The test name is defined in mockBaselineJSON. The image hashes below are not.
 	testName := types.TestName("ThisIsTheOnlyTest")
@@ -1032,8 +1016,7 @@
 func TestNegativePassFail(t *testing.T) {
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	// These are defined in mockBaselineJSON
@@ -1087,8 +1070,7 @@
 func TestPositivePassFail(t *testing.T) {
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	// These are defined in mockBaselineJSON
@@ -1137,8 +1119,7 @@
 func TestCheckSunnyDay(t *testing.T) {
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	// These are defined in mockBaselineJSON
@@ -1182,8 +1163,7 @@
 func TestCheckIssue(t *testing.T) {
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	// These are defined in mockBaselineJSON
@@ -1237,8 +1217,7 @@
 func TestCheckSunnyDayNegative(t *testing.T) {
 	unittest.SmallTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	// imgHash is not seen in expectations
@@ -1277,8 +1256,7 @@
 func TestCheckLoad(t *testing.T) {
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	imgData := []byte("some bytes")
 	// These are defined in mockBaselineJSON
@@ -1327,8 +1305,7 @@
 func TestCheckLoadFails(t *testing.T) {
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	// This should not work
 	_, err := LoadCloudClient(wd)
@@ -1354,9 +1331,8 @@
 	// It is arbitrary.
 	const otherHash = "ccc2912653148661835084a809fee263"
 
-	wd, cleanup := testutils.TempDir(t)
+	wd := t.TempDir()
 	outDir := filepath.Join(wd, "out")
-	defer cleanup()
 
 	inputPath := filepath.Join(wd, "input.png")
 	input, err := os.Create(inputPath)
@@ -1409,9 +1385,8 @@
 	const rightHash = types.Digest("bbb0dc56d0429ef3586629787666ce09")
 	const otherHash = types.Digest("ccc2912653148661835084a809fee263")
 
-	wd, cleanup := testutils.TempDir(t)
+	wd := t.TempDir()
 	outDir := filepath.Join(wd, "out")
-	defer cleanup()
 
 	inputPath := filepath.Join(wd, "input.png")
 	input, err := os.Create(inputPath)
@@ -1967,8 +1942,7 @@
 func TestCloudClient_GetDigestFromCacheOrGCS_NotInCache_DownloadsImageFromGCS_Success(t *testing.T) {
 	unittest.MediumTest(t) // This tests reads/writes a small amount of data from/to disk.
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, _, _, gcsDownloader := makeMocks()
 	gcsDownloader.AssertExpectations(t)
@@ -1994,8 +1968,7 @@
 func TestCloudClient_GetDigestFromCacheOrGCS_NotInCache_DownloadsCorruptedImageFromGCS_Failure(t *testing.T) {
 	unittest.MediumTest(t) // This tests reads/writes a small amount of data from/to disk.
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, _, _, gcsDownloader := makeMocks()
 	gcsDownloader.AssertExpectations(t)
@@ -2019,8 +1992,7 @@
 func TestCloudClient_GetDigestFromCacheOrGCS_InCache_ReadsImageFromDisk_Success(t *testing.T) {
 	unittest.MediumTest(t) // This tests reads/writes a small amount of data from/to disk.
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, _, _, _ := makeMocks()
 
@@ -2051,8 +2023,7 @@
 func TestCloudClient_GetDigestFromCacheOrGCS_InCache_ReadsCorruptedImageFromDisk_Failure(t *testing.T) {
 	unittest.MediumTest(t) // This tests reads/writes a small amount of data from/to disk.
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, _, _, _ := makeMocks()
 
@@ -2082,8 +2053,7 @@
 	// This test reads and writes a small amount of data from/to disk.
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, httpClient, _, _ := makeMocks()
 	defer httpClient.AssertExpectations(t)
@@ -2108,8 +2078,7 @@
 	// This test reads and writes a small amount of data from/to disk.
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, httpClient, _, _ := makeMocks()
 	defer httpClient.AssertExpectations(t)
@@ -2133,8 +2102,7 @@
 	// This test reads and writes a small amount of data from/to disk.
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	// Pretend "goldctl imgtest init" was called.
 	j := resultState{
@@ -2182,8 +2150,7 @@
 	// This test reads and writes a small amount of data from/to disk.
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	// Pretend "goldctl imgtest init" was called.
 	j := resultState{
@@ -2236,8 +2203,7 @@
 	// This test reads and writes a small amount of data from/to disk.
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	// Pretend "goldctl imgtest init" was called.
 	j := resultState{
@@ -2266,8 +2232,7 @@
 	// This test reads and writes a small amount of data from/to disk.
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, httpClient, _, _ := makeMocks()
 	defer httpClient.AssertExpectations(t)
@@ -2295,8 +2260,7 @@
 	// This test reads and writes a small amount of data from/to disk.
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, httpClient, _, _ := makeMocks()
 	defer httpClient.AssertExpectations(t)
@@ -2323,8 +2287,7 @@
 	// This test reads and writes a small amount of data from/to disk.
 	unittest.MediumTest(t)
 
-	wd, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	wd := t.TempDir()
 
 	ctx, httpClient, _, _ := makeMocks()
 	defer httpClient.AssertExpectations(t)
diff --git a/status/go/incremental/commits_test.go b/status/go/incremental/commits_test.go
index ec83225..5919854 100644
--- a/status/go/incremental/commits_test.go
+++ b/status/go/incremental/commits_test.go
@@ -10,7 +10,6 @@
 	"go.skia.org/infra/go/git"
 	"go.skia.org/infra/go/git/repograph"
 	git_testutils "go.skia.org/infra/go/git/testutils"
-	"go.skia.org/infra/go/testutils"
 	"go.skia.org/infra/go/testutils/unittest"
 	"go.skia.org/infra/go/util"
 	"go.skia.org/infra/go/vcsinfo"
@@ -42,8 +41,7 @@
 	gb := git_testutils.GitInit(t, ctx)
 	defer gb.Cleanup()
 	c0 := gb.CommitGen(ctx, "file1")
-	wd, cleanupWd := testutils.TempDir(t)
-	defer cleanupWd()
+	wd := t.TempDir()
 	repo, err := repograph.NewLocalGraph(ctx, gb.Dir(), wd)
 	require.NoError(t, err)
 	repos := repograph.Map{
diff --git a/task_driver/go/db/memory/memory_test.go b/task_driver/go/db/memory/memory_test.go
index 427c565..37919f6 100644
--- a/task_driver/go/db/memory/memory_test.go
+++ b/task_driver/go/db/memory/memory_test.go
@@ -5,29 +5,26 @@
 	"testing"
 
 	"github.com/stretchr/testify/require"
-	"go.skia.org/infra/go/testutils"
 	"go.skia.org/infra/go/testutils/unittest"
 	"go.skia.org/infra/task_driver/go/db"
 	"go.skia.org/infra/task_driver/go/db/shared_tests"
 )
 
-func setup(t *testing.T) (db.DB, func()) {
+func setup(t *testing.T) db.DB {
 	// Medium because we use the disk, and the test downloads from GCS.
 	unittest.LargeTest(t)
-	wd, cleanup := testutils.TempDir(t)
+	wd := t.TempDir()
 	d, err := NewInMemoryDB(path.Join(wd, "db.gob"))
 	require.NoError(t, err)
-	return d, cleanup
+	return d
 }
 
 func TestMemoryDB(t *testing.T) {
-	d, cleanup := setup(t)
-	defer cleanup()
+	d := setup(t)
 	shared_tests.TestDB(t, d)
 }
 
 func TestMemoryDBMessageOrdering(t *testing.T) {
-	d, cleanup := setup(t)
-	defer cleanup()
+	d := setup(t)
 	shared_tests.TestMessageOrdering(t, d)
 }
diff --git a/task_driver/go/lib/checkout/checkout_test.go b/task_driver/go/lib/checkout/checkout_test.go
index 97c30ed..b514897 100644
--- a/task_driver/go/lib/checkout/checkout_test.go
+++ b/task_driver/go/lib/checkout/checkout_test.go
@@ -40,8 +40,7 @@
 		require.True(t, rs.Valid())
 
 		// Create temp dir.
-		wd, cleanup := testutils.TempDir(t)
-		defer cleanup()
+		wd := t.TempDir()
 		dest := filepath.Join(wd, "repo")
 
 		// Let the caller manipulate the dir.
diff --git a/task_driver/go/lib/log_parser/log_parser_test.go b/task_driver/go/lib/log_parser/log_parser_test.go
index 4876b5c..7d96d20 100644
--- a/task_driver/go/lib/log_parser/log_parser_test.go
+++ b/task_driver/go/lib/log_parser/log_parser_test.go
@@ -80,8 +80,7 @@
 	// TODO(borenet): This test will not work on Windows.
 
 	// Write a script to generate steps.
-	tmp, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	tmp := t.TempDir()
 	slowSecondStep := filepath.Join(tmp, "script.sh")
 	testutils.WriteFile(t, slowSecondStep, `#!/bin/bash
 echo "Step1"
@@ -134,8 +133,7 @@
 // a Task Driver which uses log_parser.Run with the given TokenHandler.
 func runPythonScript(t *testing.T, fn TokenHandler, script string) *td.StepReport {
 	// Write a script to generate steps.
-	tmp, cleanup := testutils.TempDir(t)
-	defer cleanup()
+	tmp := t.TempDir()
 	scriptPath := filepath.Join(tmp, "script.py")
 	testutils.WriteFile(t, scriptPath, script)