From 263649eb9fd77ef838f2878b586e603a1dea6020 Mon Sep 17 00:00:00 2001 From: Yacov Manevich Date: Thu, 6 Feb 2025 23:18:01 +0100 Subject: [PATCH] Fail fast in tests if avalancheGo executable isn't an absolute path Currently when running ginkgo tests with --avalanchego flag with a relative path, the tests fail when trying to ascertain the rpcvm plugin path, because they execute the binary without an absolute path, and the binary path is evaluated from a wrong location. In order to make the underlying issue clear, I added a check that fails the test and warns that an absolute path must be used. Signed-off-by: Yacov Manevich --- tests/e2e/README.md | 2 +- tests/fixture/e2e/env.go | 5 ++++- tests/fixture/e2e/flags.go | 24 ++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/tests/e2e/README.md b/tests/e2e/README.md index e63d6df634bc..81dba8be1690 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -8,7 +8,7 @@ ```bash ./scripts/build.sh # Builds avalanchego for use in deploying a test network ./scripts/build_xsvm.sh # Builds xsvm for use in deploying a test network with a subnet -./bin/ginkgo -v ./tests/e2e -- --avalanchego-path=./build/avalanchego +./bin/ginkgo -v ./tests/e2e -- --avalanchego-path=$PWD/build/avalanchego # Note that the path given for --avalanchego-path must be an absolute and not a relative path. ``` See [`tests.e2e.sh`](../../scripts/tests.e2e.sh) for an example. diff --git a/tests/fixture/e2e/env.go b/tests/fixture/e2e/env.go index cfb6e8d76d39..d0ca308e7145 100644 --- a/tests/fixture/e2e/env.go +++ b/tests/fixture/e2e/env.go @@ -133,10 +133,13 @@ func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork // Start a new network if network == nil { network = desiredNetwork + avalancheBinaryPath, err := flagVars.AvalancheGoExecPath() + require.NoError(err) + StartNetwork( tc, network, - flagVars.AvalancheGoExecPath(), + avalancheBinaryPath, flagVars.PluginDir(), flagVars.NetworkShutdownDelay(), flagVars.StartNetwork(), diff --git a/tests/fixture/e2e/flags.go b/tests/fixture/e2e/flags.go index e5afcb9aa5f2..629db51ce6f0 100644 --- a/tests/fixture/e2e/flags.go +++ b/tests/fixture/e2e/flags.go @@ -7,6 +7,7 @@ import ( "flag" "fmt" "os" + "path/filepath" "time" "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" @@ -28,8 +29,27 @@ type FlagVars struct { nodeCount int } -func (v *FlagVars) AvalancheGoExecPath() string { - return v.avalancheGoExecPath +func (v *FlagVars) AvalancheGoExecPath() (string, error) { + if err := v.validateAvalancheGoExecPath(); err != nil { + return "", err + } + return v.avalancheGoExecPath, nil +} + +func (v *FlagVars) validateAvalancheGoExecPath() error { + if !filepath.IsAbs(v.avalancheGoExecPath) { + absPath, err := filepath.Abs(v.avalancheGoExecPath) + if err != nil { + return fmt.Errorf("avalanchego-path (%s) is a relative path but its absolute path cannot be determined: %w", + v.avalancheGoExecPath, err) + } + + // If the absolute path file doesn't exist, it means it won't work out of the box. + if _, err := os.Stat(absPath); err != nil { + return fmt.Errorf("avalanchego-path (%s) is a relative path but must be an absolute path", v.avalancheGoExecPath) + } + } + return nil } func (v *FlagVars) PluginDir() string {