Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions db/db_pebble_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ package db

import (
"context"
"os"
"testing"

"github.com/pkg/errors"
"github.com/stretchr/testify/require"

"github.com/iotexproject/iotex-core/v2/db/batch"
"github.com/iotexproject/iotex-core/v2/testutil"
)

type kvTest struct {
Expand All @@ -24,11 +22,7 @@ type kvTest struct {

func TestPebbleDB(t *testing.T) {
r := require.New(t)
testPath, err := os.MkdirTemp("", "test-pebble")
r.NoError(err)
defer func() {
testutil.CleanupPath(testPath)
}()
testPath := t.TempDir()

cfg := DefaultConfig
cfg.DbPath = testPath
Expand Down Expand Up @@ -131,11 +125,7 @@ func TestPebbleDB(t *testing.T) {

func TestPebbleDB_Filter(t *testing.T) {
r := require.New(t)
testPath, err := os.MkdirTemp("", "test-pebble")
r.NoError(err)
defer func() {
testutil.CleanupPath(testPath)
}()
testPath := t.TempDir()

cfg := DefaultConfig
cfg.DbPath = testPath
Expand Down Expand Up @@ -189,11 +179,7 @@ func TestPebbleDB_Filter(t *testing.T) {

func TestPebbleDB_Foreach(t *testing.T) {
r := require.New(t)
testPath, err := os.MkdirTemp("", "test-pebble")
r.NoError(err)
defer func() {
testutil.CleanupPath(testPath)
}()
testPath := t.TempDir()

cfg := DefaultConfig
cfg.DbPath = testPath
Expand Down
4 changes: 1 addition & 3 deletions server/itx/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package itx

import (
"context"
"os"
"testing"
"time"

Expand Down Expand Up @@ -84,8 +83,7 @@ func newConfig(t *testing.T) (config.Config, func()) {
require.NoError(err)
contractIndexPath, err := testutil.PathOfTempFile("contractindxer.db")
require.NoError(err)
testActionStorePath, err := os.MkdirTemp(os.TempDir(), "actionstore")
require.NoError(err)
testActionStorePath := t.TempDir()
cfg := config.Default
cfg.Genesis = genesis.TestDefault()
cfg.API.GRPCPort = testutil.RandomPort()
Expand Down