aboutsummaryrefslogtreecommitdiffstats
path: root/tests/integration/gpg_git_test.go
diff options
context:
space:
mode:
authorEng Zer Jun <engzerjun@gmail.com>2022-09-04 23:14:53 +0800
committerGitHub <noreply@github.com>2022-09-04 16:14:53 +0100
commit8b0aaa5f86e40a4699f278d09d116add63f8e4a0 (patch)
tree8133c4362e102b84c1d69df0ee09dd5a6b86b5f5 /tests/integration/gpg_git_test.go
parentc722a26e7efa69370804ac04590e9e467decc093 (diff)
downloadgitea-8b0aaa5f86e40a4699f278d09d116add63f8e4a0.tar.gz
gitea-8b0aaa5f86e40a4699f278d09d116add63f8e4a0.zip
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 <engzerjun@gmail.com>
Diffstat (limited to 'tests/integration/gpg_git_test.go')
-rw-r--r--tests/integration/gpg_git_test.go7
1 files changed, 2 insertions, 5 deletions
diff --git a/tests/integration/gpg_git_test.go b/tests/integration/gpg_git_test.go
index 2e16d150c8..80f484926d 100644
--- a/tests/integration/gpg_git_test.go
+++ b/tests/integration/gpg_git_test.go
@@ -16,7 +16,6 @@ import (
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
- "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
@@ -29,11 +28,9 @@ func TestGPGGit(t *testing.T) {
username := "user2"
// OK Set a new GPG home
- tmpDir, err := os.MkdirTemp("", "temp-gpg")
- assert.NoError(t, err)
- defer util.RemoveAll(tmpDir)
+ tmpDir := t.TempDir()
- err = os.Chmod(tmpDir, 0o700)
+ err := os.Chmod(tmpDir, 0o700)
assert.NoError(t, err)
oldGNUPGHome := os.Getenv("GNUPGHOME")