mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-31 02:01:46 +02:00
invoices: use T.TempDir
to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
9294b53fcc
commit
6c4ce69b26
@ -337,11 +337,10 @@ func TestCancelInvoice(t *testing.T) {
|
|||||||
func TestSettleHoldInvoice(t *testing.T) {
|
func TestSettleHoldInvoice(t *testing.T) {
|
||||||
defer timeout()()
|
defer timeout()()
|
||||||
|
|
||||||
cdb, cleanup, err := newTestChannelDB(clock.NewTestClock(time.Time{}))
|
cdb, err := newTestChannelDB(t, clock.NewTestClock(time.Time{}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
// Instantiate and start the invoice ctx.registry.
|
// Instantiate and start the invoice ctx.registry.
|
||||||
cfg := RegistryConfig{
|
cfg := RegistryConfig{
|
||||||
@ -510,11 +509,10 @@ func TestSettleHoldInvoice(t *testing.T) {
|
|||||||
func TestCancelHoldInvoice(t *testing.T) {
|
func TestCancelHoldInvoice(t *testing.T) {
|
||||||
defer timeout()()
|
defer timeout()()
|
||||||
|
|
||||||
cdb, cleanup, err := newTestChannelDB(clock.NewTestClock(time.Time{}))
|
cdb, err := newTestChannelDB(t, clock.NewTestClock(time.Time{}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
// Instantiate and start the invoice ctx.registry.
|
// Instantiate and start the invoice ctx.registry.
|
||||||
cfg := RegistryConfig{
|
cfg := RegistryConfig{
|
||||||
@ -935,9 +933,7 @@ func TestMppPayment(t *testing.T) {
|
|||||||
func TestInvoiceExpiryWithRegistry(t *testing.T) {
|
func TestInvoiceExpiryWithRegistry(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
cdb, cleanup, err := newTestChannelDB(clock.NewTestClock(time.Time{}))
|
cdb, err := newTestChannelDB(t, clock.NewTestClock(time.Time{}))
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -1043,9 +1039,7 @@ func TestOldInvoiceRemovalOnStart(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
testClock := clock.NewTestClock(testTime)
|
testClock := clock.NewTestClock(testTime)
|
||||||
cdb, cleanup, err := newTestChannelDB(testClock)
|
cdb, err := newTestChannelDB(t, testClock)
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
cfg := RegistryConfig{
|
cfg := RegistryConfig{
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"sync"
|
"sync"
|
||||||
@ -162,29 +161,20 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestChannelDB(clock clock.Clock) (*channeldb.DB, func(), error) {
|
func newTestChannelDB(t *testing.T, clock clock.Clock) (*channeldb.DB, error) {
|
||||||
// First, create a temporary directory to be used for the duration of
|
// Create channeldb for the first time.
|
||||||
// this test.
|
|
||||||
tempDirName, err := ioutil.TempDir("", "channeldb")
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next, create channeldb for the first time.
|
|
||||||
cdb, err := channeldb.Open(
|
cdb, err := channeldb.Open(
|
||||||
tempDirName, channeldb.OptionClock(clock),
|
t.TempDir(), channeldb.OptionClock(clock),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.RemoveAll(tempDirName)
|
return nil, err
|
||||||
return nil, nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanUp := func() {
|
t.Cleanup(func() {
|
||||||
cdb.Close()
|
cdb.Close()
|
||||||
os.RemoveAll(tempDirName)
|
})
|
||||||
}
|
|
||||||
|
|
||||||
return cdb, cleanUp, nil
|
return cdb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type testContext struct {
|
type testContext struct {
|
||||||
@ -200,7 +190,7 @@ type testContext struct {
|
|||||||
func newTestContext(t *testing.T) *testContext {
|
func newTestContext(t *testing.T) *testContext {
|
||||||
clock := clock.NewTestClock(testTime)
|
clock := clock.NewTestClock(testTime)
|
||||||
|
|
||||||
cdb, cleanup, err := newTestChannelDB(clock)
|
cdb, err := newTestChannelDB(t, clock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -221,7 +211,6 @@ func newTestContext(t *testing.T) *testContext {
|
|||||||
|
|
||||||
err = registry.Start()
|
err = registry.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cleanup()
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +224,6 @@ func newTestContext(t *testing.T) *testContext {
|
|||||||
if err = registry.Stop(); err != nil {
|
if err = registry.Stop(); err != nil {
|
||||||
t.Fatalf("failed to stop invoice registry: %v", err)
|
t.Fatalf("failed to stop invoice registry: %v", err)
|
||||||
}
|
}
|
||||||
cleanup()
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user