lnwallet: use T.TempDir to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
4 files changed
+21
-62
No files matched your search
@@ -10,7 +10,6 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -269,13 +268,12 @@ func testVectors(t *testing.T, chanType channeldb.ChannelType, test testCase) {
|
||||
|
||||
// Set up a test channel on which the test commitment transaction is
|
||||
// going to be produced.
|
||||
remoteChannel, localChannel, cleanUp := createTestChannelsForVectors(
|
||||
remoteChannel, localChannel := createTestChannelsForVectors(
|
||||
tc,
|
||||
chanType, test.FeePerKw,
|
||||
remoteBalance.ToSatoshis(),
|
||||
localBalance.ToSatoshis(),
|
||||
)
|
||||
defer cleanUp()
|
||||
|
||||
// Add htlcs (if any) to the update logs of both sides and save a hash
|
||||
// map that allows us to identify the htlcs in the scripts later on and
|
||||
@@ -747,7 +745,7 @@ func (p *mockProducer) Encode(w io.Writer) error {
|
||||
// test channel that is used to verify the test vectors.
|
||||
func createTestChannelsForVectors(tc *testContext, chanType channeldb.ChannelType,
|
||||
feeRate btcutil.Amount, remoteBalance, localBalance btcutil.Amount) (
|
||||
*LightningChannel, *LightningChannel, func()) {
|
||||
*LightningChannel, *LightningChannel) {
|
||||
|
||||
t := tc.t
|
||||
|
||||
@@ -846,16 +844,10 @@ func createTestChannelsForVectors(tc *testContext, chanType channeldb.ChannelTyp
|
||||
)
|
||||
|
||||
// Create temporary databases.
|
||||
remotePath, err := ioutil.TempDir("", "remotedb")
|
||||
dbRemote, err := channeldb.Open(t.TempDir())
|
||||
require.NoError(t, err)
|
||||
|
||||
dbRemote, err := channeldb.Open(remotePath)
|
||||
require.NoError(t, err)
|
||||
|
||||
localPath, err := ioutil.TempDir("", "localdb")
|
||||
require.NoError(t, err)
|
||||
|
||||
dbLocal, err := channeldb.Open(localPath)
|
||||
dbLocal, err := channeldb.Open(t.TempDir())
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create the initial commitment transactions for the channel.
|
||||
@@ -1005,16 +997,13 @@ func createTestChannelsForVectors(tc *testContext, chanType channeldb.ChannelTyp
|
||||
|
||||
// Return a clean up function that stops goroutines and removes the test
|
||||
// databases.
|
||||
cleanUpFunc := func() {
|
||||
t.Cleanup(func() {
|
||||
dbLocal.Close()
|
||||
dbRemote.Close()
|
||||
|
||||
os.RemoveAll(localPath)
|
||||
os.RemoveAll(remotePath)
|
||||
|
||||
require.NoError(t, remotePool.Stop())
|
||||
require.NoError(t, localPool.Stop())
|
||||
}
|
||||
})
|
||||
|
||||
return channelRemote, channelLocal, cleanUpFunc
|
||||
return channelRemote, channelLocal
|
||||
}
|
||||
Reference in new issue
Block a user