From ca7564e4b4504cacfe63ab098bef516d5bbeb84c Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Wed, 4 Nov 2020 11:03:31 +0100 Subject: [PATCH] itest: add flags for lnd executable --- lntest/itest/lnd_test.go | 17 +---------------- lntest/itest/test_harness.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index c2ceac58..e49c7090 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -14,7 +14,6 @@ import ( "os" "path/filepath" "reflect" - "runtime" "strings" "sync" "sync/atomic" @@ -14213,23 +14212,9 @@ func TestLightningNetworkDaemon(t *testing.T) { t, chainBackend.ConnectMiner(), "failed to connect to miner", ) - binary := itestLndBinary - if runtime.GOOS == "windows" { - // Windows (even in a bash like environment like git bash as on - // Travis) doesn't seem to like relative paths to exe files... - currentDir, err := os.Getwd() - if err != nil { - ht.Fatalf("unable to get working directory: %v", err) - } - targetPath := filepath.Join(currentDir, "../../lnd-itest.exe") - binary, err = filepath.Abs(targetPath) - if err != nil { - ht.Fatalf("unable to get absolute path: %v", err) - } - } - // Now we can set up our test harness (LND instance), with the chain // backend we just created. + binary := ht.getLndBinary() lndHarness, err = lntest.NewNetworkHarness(miner, chainBackend, binary) if err != nil { ht.Fatalf("unable to create lightning network harness: %v", err) diff --git a/lntest/itest/test_harness.go b/lntest/itest/test_harness.go index a3c47528..45248f60 100644 --- a/lntest/itest/test_harness.go +++ b/lntest/itest/test_harness.go @@ -3,8 +3,12 @@ package itest import ( "bytes" "context" + "flag" "fmt" "math" + "os" + "path/filepath" + "runtime" "testing" "time" @@ -20,6 +24,11 @@ import ( var ( harnessNetParams = &chaincfg.RegressionNetParams + + // lndExecutable is the full path to the lnd binary. + lndExecutable = flag.String( + "lndexec", itestLndBinary, "full path to lnd binary", + ) ) const ( @@ -111,6 +120,31 @@ func (h *harnessTest) Log(args ...interface{}) { h.t.Log(args...) } +func (h *harnessTest) getLndBinary() string { + binary := itestLndBinary + lndExec := "" + if lndExecutable != nil && *lndExecutable != "" { + lndExec = *lndExecutable + } + if lndExec == "" && runtime.GOOS == "windows" { + // Windows (even in a bash like environment like git bash as on + // Travis) doesn't seem to like relative paths to exe files... + currentDir, err := os.Getwd() + if err != nil { + h.Fatalf("unable to get working directory: %v", err) + } + targetPath := filepath.Join(currentDir, "../../lnd-itest.exe") + binary, err = filepath.Abs(targetPath) + if err != nil { + h.Fatalf("unable to get absolute path: %v", err) + } + } else if lndExec != "" { + binary = lndExec + } + + return binary +} + type testCase struct { name string test func(net *lntest.NetworkHarness, t *harnessTest)