aliasmgr: use T.TempDir to create temporary test directory

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun committed 2022-08-24 08:58:11 +08:00
1 parent f8615f9910
commit 1cd7e3aee6
1 file changed
+2 -12
+2 -12
View File
@@ -1,9 +1,7 @@
package aliasmgr package aliasmgr
import ( import (
"io/ioutil"
"math/rand" "math/rand"
"os"
"path/filepath" "path/filepath"
"testing" "testing"
@@ -18,11 +16,7 @@ func TestAliasStorePeerAlias(t *testing.T) {
t.Parallel() t.Parallel()
// Create the backend database and use this to create the aliasStore. // Create the backend database and use this to create the aliasStore.
dbDir, err := ioutil.TempDir("", "aliasStore") dbPath := filepath.Join(t.TempDir(), "testdb")
require.NoError(t, err)
defer os.RemoveAll(dbDir)
dbPath := filepath.Join(dbDir, "testdb")
db, err := kvdb.Create( db, err := kvdb.Create(
kvdb.BoltBackendName, dbPath, true, kvdb.DefaultDBTimeout, kvdb.BoltBackendName, dbPath, true, kvdb.DefaultDBTimeout,
) )
@@ -51,11 +45,7 @@ func TestAliasStoreRequest(t *testing.T) {
t.Parallel() t.Parallel()
// Create the backend database and use this to create the aliasStore. // Create the backend database and use this to create the aliasStore.
dbDir, err := ioutil.TempDir("", "aliasStore") dbPath := filepath.Join(t.TempDir(), "testdb")
require.NoError(t, err)
defer os.RemoveAll(dbDir)
dbPath := filepath.Join(dbDir, "testdb")
db, err := kvdb.Create( db, err := kvdb.Create(
kvdb.BoltBackendName, dbPath, true, kvdb.DefaultDBTimeout, kvdb.BoltBackendName, dbPath, true, kvdb.DefaultDBTimeout,
) )