mirror of
https://github.com/go-gitea/gitea
synced 2025-07-08 03:27:19 +00:00
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>
This commit is contained in:
@ -25,15 +25,12 @@ func str2url(raw string) *url.URL {
|
||||
func TestDetermineLocalEndpoint(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
root, _ := os.MkdirTemp("", "lfs_test")
|
||||
defer os.RemoveAll(root)
|
||||
root := t.TempDir()
|
||||
|
||||
rootdotgit, _ := os.MkdirTemp("", "lfs_test")
|
||||
defer os.RemoveAll(rootdotgit)
|
||||
rootdotgit := t.TempDir()
|
||||
os.Mkdir(filepath.Join(rootdotgit, ".git"), 0o700)
|
||||
|
||||
lfsroot, _ := os.MkdirTemp("", "lfs_test")
|
||||
defer os.RemoveAll(lfsroot)
|
||||
lfsroot := t.TempDir()
|
||||
|
||||
// Test cases
|
||||
cases := []struct {
|
||||
|
Reference in New Issue
Block a user