From 8b0aaa5f86e40a4699f278d09d116add63f8e4a0 Mon Sep 17 00:00:00 2001 From: Eng Zer Jun Date: Sun, 4 Sep 2022 23:14:53 +0800 Subject: test: use `T.TempDir` to create temporary test directory (#21043) A testing cleanup. This pull request replaces `os.MkdirTemp` with `t.TempDir`. We can use the `T.TempDir` function from the `testing` package to create temporary directory. The directory created by `T.TempDir` is automatically removed when the test and all its subtests complete. This saves us at least 2 lines (error check, and cleanup) on every instance, or in some cases adds cleanup that we forgot. Reference: https://pkg.go.dev/testing#T.TempDir ```go func TestFoo(t *testing.T) { // before tmpDir, err := os.MkdirTemp("", "") require.NoError(t, err) defer os.RemoveAll(tmpDir) // now tmpDir := t.TempDir() } ``` Signed-off-by: Eng Zer Jun --- tests/integration/git_clone_wiki_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/integration/git_clone_wiki_test.go') diff --git a/tests/integration/git_clone_wiki_test.go b/tests/integration/git_clone_wiki_test.go index 4bdbc9b7c3..3e10b17d40 100644 --- a/tests/integration/git_clone_wiki_test.go +++ b/tests/integration/git_clone_wiki_test.go @@ -35,8 +35,7 @@ func TestRepoCloneWiki(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { defer tests.PrepareTestEnv(t)() - dstPath, err := os.MkdirTemp("", "clone_wiki") - assert.NoError(t, err) + dstPath := t.TempDir() r := fmt.Sprintf("%suser2/repo1.wiki.git", u.String()) u, _ = url.Parse(r) -- cgit v1.2.3