diff --git a/kvdb/bolt_fixture.go b/kvdb/bolt_fixture.go index d78e1ece3..0ac54b55f 100644 --- a/kvdb/bolt_fixture.go +++ b/kvdb/bolt_fixture.go @@ -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) diff --git a/kvdb/bolt_test.go b/kvdb/bolt_test.go index a6cec252b..69366c5b5 100644 --- a/kvdb/bolt_test.go +++ b/kvdb/bolt_test.go @@ -76,7 +76,6 @@ func TestBolt(t *testing.T) { t.Parallel() f := NewBoltFixture(t) - defer f.Cleanup() test.test(t, f.NewBackend()) }) diff --git a/kvdb/etcd/fixture.go b/kvdb/etcd/fixture.go index 4dde37cc9..8f0e0af7f 100644 --- a/kvdb/etcd/fixture.go +++ b/kvdb/etcd/fixture.go @@ -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) } @@ -69,13 +63,10 @@ func NewEtcdTestFixture(t *testing.T) *EtcdTestFixture { cli.Lease = namespace.NewLease(cli.Lease, defaultNamespace) return &EtcdTestFixture{ - t: t, - cli: cli, - config: config, - cleanup: func() { - etcdCleanup() - os.RemoveAll(tmpDir) - }, + t: t, + cli: cli, + config: config, + cleanup: etcdCleanup, } }