fix: using t.TempDir() to simplify test temp dir manager (#23893)

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
This commit is contained in:
petersssong 2025-03-06 23:45:51 +08:00 committed by GitHub
parent 982dc981ad
commit 159bba145f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 16 deletions

View File

@ -2,7 +2,6 @@ package tests
import (
"context"
"os"
"strings"
"testing"
@ -69,11 +68,7 @@ func testInitSchema(t *testing.T, disableRetainDeletions bool, goldenFileName st
func createTestDB(t *testing.T) (connectionUrl string) {
t.Helper()
tempDir, err := os.MkdirTemp("", "postgres-indexer-test")
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, os.RemoveAll(tempDir))
})
tempDir := t.TempDir()
dbPort := freeport.GetOne(t)
pgConfig := embeddedpostgres.DefaultConfig().

View File

@ -2,7 +2,6 @@ package tests
import (
"context"
"os"
"strings"
"testing"
@ -31,8 +30,7 @@ func TestPostgresIndexer(t *testing.T) {
func testPostgresIndexer(t *testing.T, retainDeletions bool) {
t.Helper()
tempDir, err := os.MkdirTemp("", "postgres-indexer-test")
require.NoError(t, err)
tempDir := t.TempDir()
dbPort := freeport.GetOne(t)
pgConfig := embeddedpostgres.DefaultConfig().
@ -48,8 +46,6 @@ func testPostgresIndexer(t *testing.T, retainDeletions bool) {
t.Cleanup(func() {
cancel()
require.NoError(t, pg.Stop())
err := os.RemoveAll(tempDir)
require.NoError(t, err)
})
debugLog := &strings.Builder{}

View File

@ -14,11 +14,7 @@ import (
// Ensures that CollectTx correctly traverses directories and won't error out on encountering
// a directory during traversal of the first level. See issue https://github.com/cosmos/cosmos-sdk/issues/6788.
func TestCollectTxsHandlesDirectories(t *testing.T) {
testDir, err := os.MkdirTemp(os.TempDir(), "testCollectTxs")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(testDir)
testDir := t.TempDir()
// 1. We'll insert a directory as the first element before JSON file.
subDirPath := filepath.Join(testDir, "_adir")