Skip to content

Commit d4e648a

Browse files
committed
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 <[email protected]>
1 parent 2641b53 commit d4e648a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tests/e2e/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
```bash
99
./scripts/build.sh # Builds avalanchego for use in deploying a test network
1010
./scripts/build_xsvm.sh # Builds xsvm for use in deploying a test network with a subnet
11-
./bin/ginkgo -v ./tests/e2e -- --avalanchego-path=./build/avalanchego
11+
./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.
1212
```
1313

1414
See [`tests.e2e.sh`](../../scripts/tests.e2e.sh) for an example.

tests/fixture/e2e/flags.go

+18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"flag"
88
"fmt"
99
"os"
10+
"path/filepath"
1011
"time"
1112

1213
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
@@ -29,9 +30,26 @@ type FlagVars struct {
2930
}
3031

3132
func (v *FlagVars) AvalancheGoExecPath() string {
33+
v.validateAvalancheGoExecPath()
3234
return v.avalancheGoExecPath
3335
}
3436

37+
func (v *FlagVars) validateAvalancheGoExecPath() {
38+
if !filepath.IsAbs(v.avalancheGoExecPath) {
39+
absPath, err := filepath.Abs(v.avalancheGoExecPath)
40+
if err != nil {
41+
fmt.Fprintf(os.Stderr, "avalanchego-path (%s) is a relative path but its absolute path cannot be determined: %v\n",
42+
v.avalancheGoExecPath, err)
43+
}
44+
45+
// If the absolute path file doesn't exist, it means it won't work out of the box.
46+
if _, err := os.Stat(absPath); err != nil {
47+
fmt.Fprintf(os.Stderr, "avalanchego-path (%s) is a relative path but must be an absolute path\n", v.avalancheGoExecPath)
48+
os.Exit(2)
49+
}
50+
}
51+
}
52+
3553
func (v *FlagVars) PluginDir() string {
3654
return v.pluginDir
3755
}

0 commit comments

Comments
 (0)