Skip to content

Commit 538cb7b

Browse files
refactor: use t.TempDir() instead of os.MkdirTemp (#4575)
Signed-off-by: yuhangcangqian <[email protected]> Co-authored-by: CoderZhi <[email protected]>
1 parent 51efd60 commit 538cb7b

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

db/db_pebble_test.go

+3-17
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ package db
77

88
import (
99
"context"
10-
"os"
1110
"testing"
1211

1312
"github.com/pkg/errors"
1413
"github.com/stretchr/testify/require"
1514

1615
"github.com/iotexproject/iotex-core/v2/db/batch"
17-
"github.com/iotexproject/iotex-core/v2/testutil"
1816
)
1917

2018
type kvTest struct {
@@ -24,11 +22,7 @@ type kvTest struct {
2422

2523
func TestPebbleDB(t *testing.T) {
2624
r := require.New(t)
27-
testPath, err := os.MkdirTemp("", "test-pebble")
28-
r.NoError(err)
29-
defer func() {
30-
testutil.CleanupPath(testPath)
31-
}()
25+
testPath := t.TempDir()
3226

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

132126
func TestPebbleDB_Filter(t *testing.T) {
133127
r := require.New(t)
134-
testPath, err := os.MkdirTemp("", "test-pebble")
135-
r.NoError(err)
136-
defer func() {
137-
testutil.CleanupPath(testPath)
138-
}()
128+
testPath := t.TempDir()
139129

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

190180
func TestPebbleDB_Foreach(t *testing.T) {
191181
r := require.New(t)
192-
testPath, err := os.MkdirTemp("", "test-pebble")
193-
r.NoError(err)
194-
defer func() {
195-
testutil.CleanupPath(testPath)
196-
}()
182+
testPath := t.TempDir()
197183

198184
cfg := DefaultConfig
199185
cfg.DbPath = testPath

server/itx/server_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package itx
77

88
import (
99
"context"
10-
"os"
1110
"testing"
1211
"time"
1312

@@ -84,8 +83,7 @@ func newConfig(t *testing.T) (config.Config, func()) {
8483
require.NoError(err)
8584
contractIndexPath, err := testutil.PathOfTempFile("contractindxer.db")
8685
require.NoError(err)
87-
testActionStorePath, err := os.MkdirTemp(os.TempDir(), "actionstore")
88-
require.NoError(err)
86+
testActionStorePath := t.TempDir()
8987
cfg := config.Default
9088
cfg.Genesis = genesis.TestDefault()
9189
cfg.API.GRPCPort = testutil.RandomPort()

0 commit comments

Comments
 (0)