mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 22:25:24 +01:00
kvdb: use T.TempDir
to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
d926ad1f84
commit
0edc16aa01
3 changed files with 6 additions and 25 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -76,7 +76,6 @@ func TestBolt(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
f := NewBoltFixture(t)
|
||||
defer f.Cleanup()
|
||||
|
||||
test.test(t, f.NewBackend())
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue