Skip to content

Commit 263649e

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 263649e

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
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/env.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,13 @@ func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork
133133
// Start a new network
134134
if network == nil {
135135
network = desiredNetwork
136+
avalancheBinaryPath, err := flagVars.AvalancheGoExecPath()
137+
require.NoError(err)
138+
136139
StartNetwork(
137140
tc,
138141
network,
139-
flagVars.AvalancheGoExecPath(),
142+
avalancheBinaryPath,
140143
flagVars.PluginDir(),
141144
flagVars.NetworkShutdownDelay(),
142145
flagVars.StartNetwork(),

tests/fixture/e2e/flags.go

+22-2
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"
@@ -28,8 +29,27 @@ type FlagVars struct {
2829
nodeCount int
2930
}
3031

31-
func (v *FlagVars) AvalancheGoExecPath() string {
32-
return v.avalancheGoExecPath
32+
func (v *FlagVars) AvalancheGoExecPath() (string, error) {
33+
if err := v.validateAvalancheGoExecPath(); err != nil {
34+
return "", err
35+
}
36+
return v.avalancheGoExecPath, nil
37+
}
38+
39+
func (v *FlagVars) validateAvalancheGoExecPath() error {
40+
if !filepath.IsAbs(v.avalancheGoExecPath) {
41+
absPath, err := filepath.Abs(v.avalancheGoExecPath)
42+
if err != nil {
43+
return fmt.Errorf("avalanchego-path (%s) is a relative path but its absolute path cannot be determined: %w",
44+
v.avalancheGoExecPath, err)
45+
}
46+
47+
// If the absolute path file doesn't exist, it means it won't work out of the box.
48+
if _, err := os.Stat(absPath); err != nil {
49+
return fmt.Errorf("avalanchego-path (%s) is a relative path but must be an absolute path", v.avalancheGoExecPath)
50+
}
51+
}
52+
return nil
3353
}
3454

3555
func (v *FlagVars) PluginDir() string {

0 commit comments

Comments
 (0)