Skip to content

Commit

Permalink
Fail fast in tests if avalancheGo executable isn't an absolute path
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
yacovm committed Feb 6, 2025
1 parent 2641b53 commit 51828a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions tests/fixture/e2e/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"time"

"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
Expand All @@ -32,6 +33,22 @@ func (v *FlagVars) AvalancheGoExecPath() string {
return v.avalancheGoExecPath
}

func (v *FlagVars) validateAvalancheGoExecPath() {
if !filepath.IsAbs(v.avalancheGoExecPath) {
absPath, err := filepath.Abs(v.avalancheGoExecPath)
if err != nil {
fmt.Fprintf(os.Stderr, "avalanchego-path (%s) is a relative path but its absolute path cannot be determined: %v\n",
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 {
fmt.Fprintf(os.Stderr, "avalanchego-path (%s) is a relative path but must be an absolute path\n", v.avalancheGoExecPath)
os.Exit(2)
}
}
}

func (v *FlagVars) PluginDir() string {
return v.pluginDir
}
Expand Down

0 comments on commit 51828a0

Please sign in to comment.