Skip to content

Commit 497c9c0

Browse files
committed
made path to go binary configurable
1 parent c540bdc commit 497c9c0

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

op-nat/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Config struct {
1515
TestDir string
1616
ValidatorConfig string
1717
TargetGate string
18+
GoBinary string
1819

1920
Log log.Logger
2021
}
@@ -49,6 +50,7 @@ func NewConfig(ctx *cli.Context, log log.Logger, testDir string, validatorConfig
4950
TestDir: absTestDir,
5051
ValidatorConfig: absValidatorConfig,
5152
TargetGate: gate,
53+
GoBinary: ctx.String(flags.GoBinary.Name),
5254
Log: log,
5355
}, nil
5456
}

op-nat/flags/flags.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ var (
3535
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "GATE"),
3636
Usage: "Gate to run (eg. 'alphanet')",
3737
}
38+
GoBinary = &cli.StringFlag{
39+
Name: "go-binary",
40+
Value: "go",
41+
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "GO_BINARY"),
42+
Usage: "Path to the Go binary to use for running tests",
43+
}
3844
)
3945

4046
var requiredFlags = []cli.Flag{
@@ -43,7 +49,9 @@ var requiredFlags = []cli.Flag{
4349
Gate,
4450
}
4551

46-
var optionalFlags []cli.Flag
52+
var optionalFlags = []cli.Flag{
53+
GoBinary,
54+
}
4755
var Flags []cli.Flag
4856

4957
func init() {

op-nat/nat.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func New(ctx context.Context, config *Config, version string) (*nat, error) {
5555
WorkDir: config.TestDir,
5656
Log: config.Log,
5757
TargetGate: config.TargetGate,
58+
GoBinary: config.GoBinary,
5859
})
5960
if err != nil {
6061
return nil, fmt.Errorf("failed to create test runner: %w", err)

op-nat/runner/runner.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ type runner struct {
7070
workDir string // Directory for running tests
7171
log log.Logger
7272
runID string
73-
timeout time.Duration // Add timeout configuration
73+
timeout time.Duration // Test timeout
74+
goBinary string // Path to the Go binary
7475
}
7576

7677
type Config struct {
7778
Registry *registry.Registry
7879
TargetGate string
7980
WorkDir string
8081
Log log.Logger
81-
Timeout time.Duration // Add timeout configuration
82+
Timeout time.Duration // Test timeout
83+
GoBinary string // path to the Go binary
8284
}
8385

8486
// NewTestRunner creates a new test runner instance
@@ -109,12 +111,17 @@ func NewTestRunner(cfg Config) (TestRunner, error) {
109111
cfg.Timeout = 5 * time.Minute // Default timeout
110112
}
111113

114+
if cfg.GoBinary == "" {
115+
cfg.GoBinary = "go" // Default to "go" if not specified
116+
}
117+
112118
return &runner{
113119
registry: cfg.Registry,
114120
validators: validators,
115121
workDir: cfg.WorkDir,
116122
log: cfg.Log,
117123
timeout: cfg.Timeout,
124+
goBinary: cfg.GoBinary,
118125
}, nil
119126
}
120127

@@ -329,7 +336,7 @@ func (r *runner) listTestsInPackage(pkg string) ([]string, error) {
329336
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) // Shorter timeout for listing
330337
defer cancel()
331338

332-
listCmd := exec.CommandContext(ctx, "go", "test", pkg, "-list", "^Test")
339+
listCmd := exec.CommandContext(ctx, r.goBinary, "test", pkg, "-list", "^Test")
333340
listCmd.Dir = r.workDir
334341
var listOut, listOutErr bytes.Buffer
335342
listCmd.Stdout = &listOut
@@ -392,7 +399,7 @@ func (r *runner) runSingleTest(metadata types.ValidatorMetadata) (*types.TestRes
392399
defer cancel()
393400

394401
args := r.buildTestArgs(metadata)
395-
cmd := exec.CommandContext(ctx, "go", args...)
402+
cmd := exec.CommandContext(ctx, r.goBinary, args...)
396403
cmd.Dir = r.workDir
397404

398405
var stdout, stderr bytes.Buffer
@@ -403,7 +410,8 @@ func (r *runner) runSingleTest(metadata types.ValidatorMetadata) (*types.TestRes
403410
"dir", cmd.Dir,
404411
"package", metadata.Package,
405412
"command", cmd.String(),
406-
"timeout", r.timeout)
413+
"timeout", r.timeout,
414+
"goBinary", r.goBinary)
407415

408416
result := types.TestResult{
409417
Metadata: metadata,

0 commit comments

Comments
 (0)