lntest: specify lnd binary

Integration tests in external projects might not have the same folder
structure as lnd does. Therefore we want to allow the path to the
lnd itest binary to be configurable.
This commit is contained in:
Oliver Gugger committed 2020-01-03 09:17:23 +01:00
1 parent b762d441cf
commit ce711a1de7
3 files changed
+17 -7

No files matched your search

+11 -4
View File
@@ -35,6 +35,10 @@ const DefaultCSV = 4
type NetworkHarness struct { type NetworkHarness struct {
netParams *chaincfg.Params netParams *chaincfg.Params
// lndBinary is the full path to the lnd binary that was specifically
// compiled with all required itest flags.
lndBinary string
// Miner is a reference to a running full node that can be used to create // Miner is a reference to a running full node that can be used to create
// new blocks on the network. // new blocks on the network.
Miner *rpctest.Harness Miner *rpctest.Harness
@@ -68,7 +72,9 @@ type NetworkHarness struct {
// TODO(roasbeef): add option to use golang's build library to a binary of the // TODO(roasbeef): add option to use golang's build library to a binary of the
// current repo. This will save developers from having to manually `go install` // current repo. This will save developers from having to manually `go install`
// within the repo each time before changes // within the repo each time before changes
func NewNetworkHarness(r *rpctest.Harness, b BackendConfig) (*NetworkHarness, error) { func NewNetworkHarness(r *rpctest.Harness, b BackendConfig, lndBinary string) (
*NetworkHarness, error) {
n := NetworkHarness{ n := NetworkHarness{
activeNodes: make(map[int]*HarnessNode), activeNodes: make(map[int]*HarnessNode),
nodesByPub: make(map[string]*HarnessNode), nodesByPub: make(map[string]*HarnessNode),
@@ -79,6 +85,7 @@ func NewNetworkHarness(r *rpctest.Harness, b BackendConfig) (*NetworkHarness, er
Miner: r, Miner: r,
BackendCfg: b, BackendCfg: b,
quit: make(chan struct{}), quit: make(chan struct{}),
lndBinary: lndBinary,
} }
go n.networkWatcher() go n.networkWatcher()
return &n, nil return &n, nil
@@ -361,7 +368,7 @@ func (n *NetworkHarness) newNode(name string, extraArgs []string,
n.activeNodes[node.NodeID] = node n.activeNodes[node.NodeID] = node
n.mtx.Unlock() n.mtx.Unlock()
if err := node.start(n.lndErrorChan); err != nil { if err := node.start(n.lndBinary, n.lndErrorChan); err != nil {
return nil, err return nil, err
} }
@@ -612,7 +619,7 @@ func (n *NetworkHarness) RestartNode(node *HarnessNode, callback func() error,
} }
} }
if err := node.start(n.lndErrorChan); err != nil { if err := node.start(n.lndBinary, n.lndErrorChan); err != nil {
return err return err
} }
@@ -643,7 +650,7 @@ func (n *NetworkHarness) SuspendNode(node *HarnessNode) (func() error, error) {
} }
restart := func() error { restart := func() error {
return node.start(n.lndErrorChan) return node.start(n.lndBinary, n.lndErrorChan)
} }
return restart, nil return restart, nil
+4 -1
View File
@@ -56,6 +56,7 @@ const (
minerMempoolTimeout = lntest.MinerMempoolTimeout minerMempoolTimeout = lntest.MinerMempoolTimeout
channelOpenTimeout = lntest.ChannelOpenTimeout channelOpenTimeout = lntest.ChannelOpenTimeout
channelCloseTimeout = lntest.ChannelCloseTimeout channelCloseTimeout = lntest.ChannelCloseTimeout
itestLndBinary = "../../lnd-itest"
) )
// harnessTest wraps a regular testing.T providing enhanced error detection // harnessTest wraps a regular testing.T providing enhanced error detection
@@ -15237,7 +15238,9 @@ func TestLightningNetworkDaemon(t *testing.T) {
// Now we can set up our test harness (LND instance), with the chain // Now we can set up our test harness (LND instance), with the chain
// backend we just created. // backend we just created.
lndHarness, err = lntest.NewNetworkHarness(miner, chainBackend) lndHarness, err = lntest.NewNetworkHarness(
miner, chainBackend, itestLndBinary,
)
if err != nil { if err != nil {
ht.Fatalf("unable to create lightning network harness: %v", err) ht.Fatalf("unable to create lightning network harness: %v", err)
} }
+2 -2
View File
@@ -369,11 +369,11 @@ func (hn *HarnessNode) InvoiceMacPath() string {
// //
// This may not clean up properly if an error is returned, so the caller should // This may not clean up properly if an error is returned, so the caller should
// call shutdown() regardless of the return value. // call shutdown() regardless of the return value.
func (hn *HarnessNode) start(lndError chan<- error) error { func (hn *HarnessNode) start(lndBinary string, lndError chan<- error) error {
hn.quit = make(chan struct{}) hn.quit = make(chan struct{})
args := hn.Cfg.genArgs() args := hn.Cfg.genArgs()
hn.cmd = exec.Command("../../lnd-itest", args...) hn.cmd = exec.Command(lndBinary, args...)
// Redirect stderr output to buffer // Redirect stderr output to buffer
var errb bytes.Buffer var errb bytes.Buffer