refactor: use t.TempDir() instead of os.MkdirTemp (#1832)

Signed-off-by: yuhangcangqian <cuibuwei@qq.com>
This commit is contained in:
yuhangcangqian
2025-03-13 07:21:56 +08:00
committed by GitHub
parent 5c21e974ee
commit 138419e7a8
2 changed files with 2 additions and 10 deletions

View File

@@ -28,7 +28,7 @@ func TestWrite(t *testing.T) {
}
var tests []testTable
tempDir := filepath.Join(os.TempDir(), "gct-temp")
tempDir := t.TempDir()
testFile := filepath.Join(tempDir, "gcttest.txt")
switch runtime.GOOS {
case "windows":
@@ -49,10 +49,6 @@ func TestWrite(t *testing.T) {
t.Errorf("Test %d failed, unexpected err %s\n", x, err)
}
}
if err := os.RemoveAll(tempDir); err != nil {
t.Errorf("unable to remove temp test dir %s, manual deletion required", tempDir)
}
}
func TestMove(t *testing.T) {

View File

@@ -498,13 +498,9 @@ func setupTest(t *testing.T) {
}
}
var err error
testhelpers.MigrationDir = filepath.Join("..", "..", "database", "migrations")
testhelpers.PostgresTestDatabase = testhelpers.GetConnectionDetails()
testhelpers.TempDir, err = os.MkdirTemp("", "gct-temp")
if err != nil {
t.Fatalf("failed to create temp file: %v", err)
}
testhelpers.TempDir = t.TempDir()
}
func TestStoreInDatabase(t *testing.T) {