kvdb: 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 2022-08-15 21:07:05 +08:00
parent d926ad1f84
commit 0edc16aa01
No known key found for this signature in database
GPG key ID: DAEBBD2E34C111E6
3 changed files with 6 additions and 25 deletions

View file

@ -1,8 +1,6 @@
package kvdb
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -16,19 +14,12 @@ type boltFixture struct {
}
func NewBoltFixture(t *testing.T) *boltFixture {
tempDir, err := ioutil.TempDir("", "test")
require.NoError(t, err)
return &boltFixture{
t: t,
tempDir: tempDir,
tempDir: t.TempDir(),
}
}
func (b *boltFixture) Cleanup() {
os.RemoveAll(b.tempDir)
}
func (b *boltFixture) NewBackend() walletdb.DB {
dbPath := filepath.Join(b.tempDir)

View file

@ -76,7 +76,6 @@ func TestBolt(t *testing.T) {
t.Parallel()
f := NewBoltFixture(t)
defer f.Cleanup()
test.test(t, f.NewBackend())
})

View file

@ -5,8 +5,6 @@ package etcd
import (
"context"
"io/ioutil"
"os"
"testing"
"time"
@ -46,10 +44,7 @@ func NewTestEtcdInstance(t *testing.T, path string) (*Config, func()) {
// NewTestEtcdTestFixture creates a new etcd-test fixture. This is helper
// object to facilitate etcd tests and ensure pre and post conditions.
func NewEtcdTestFixture(t *testing.T) *EtcdTestFixture {
tmpDir, err := ioutil.TempDir("", "etcd")
if err != nil {
t.Fatalf("unable to create temp dir: %v", err)
}
tmpDir := t.TempDir()
config, etcdCleanup := NewTestEtcdInstance(t, tmpDir)
@ -59,7 +54,6 @@ func NewEtcdTestFixture(t *testing.T) *EtcdTestFixture {
Password: config.Pass,
})
if err != nil {
os.RemoveAll(tmpDir)
t.Fatalf("unable to create etcd test fixture: %v", err)
}
@ -72,10 +66,7 @@ func NewEtcdTestFixture(t *testing.T) *EtcdTestFixture {
t: t,
cli: cli,
config: config,
cleanup: func() {
etcdCleanup()
os.RemoveAll(tmpDir)
},
cleanup: etcdCleanup,
}
}