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 2019-12-17 15:01:23 +01:00
parent b762d441cf
commit ce711a1de7
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
3 changed files with 17 additions and 7 deletions

@ -35,6 +35,10 @@ const DefaultCSV = 4
type NetworkHarness struct {
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
// new blocks on the network.
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
// current repo. This will save developers from having to manually `go install`
// 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{
activeNodes: make(map[int]*HarnessNode),
nodesByPub: make(map[string]*HarnessNode),
@ -79,6 +85,7 @@ func NewNetworkHarness(r *rpctest.Harness, b BackendConfig) (*NetworkHarness, er
Miner: r,
BackendCfg: b,
quit: make(chan struct{}),
lndBinary: lndBinary,
}
go n.networkWatcher()
return &n, nil
@ -361,7 +368,7 @@ func (n *NetworkHarness) newNode(name string, extraArgs []string,
n.activeNodes[node.NodeID] = node
n.mtx.Unlock()
if err := node.start(n.lndErrorChan); err != nil {
if err := node.start(n.lndBinary, n.lndErrorChan); err != nil {
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
}
@ -643,7 +650,7 @@ func (n *NetworkHarness) SuspendNode(node *HarnessNode) (func() error, error) {
}
restart := func() error {
return node.start(n.lndErrorChan)
return node.start(n.lndBinary, n.lndErrorChan)
}
return restart, nil

@ -56,6 +56,7 @@ const (
minerMempoolTimeout = lntest.MinerMempoolTimeout
channelOpenTimeout = lntest.ChannelOpenTimeout
channelCloseTimeout = lntest.ChannelCloseTimeout
itestLndBinary = "../../lnd-itest"
)
// 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
// backend we just created.
lndHarness, err = lntest.NewNetworkHarness(miner, chainBackend)
lndHarness, err = lntest.NewNetworkHarness(
miner, chainBackend, itestLndBinary,
)
if err != nil {
ht.Fatalf("unable to create lightning network harness: %v", err)
}

@ -369,11 +369,11 @@ func (hn *HarnessNode) InvoiceMacPath() string {
//
// This may not clean up properly if an error is returned, so the caller should
// 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{})
args := hn.Cfg.genArgs()
hn.cmd = exec.Command("../../lnd-itest", args...)
hn.cmd = exec.Command(lndBinary, args...)
// Redirect stderr output to buffer
var errb bytes.Buffer