Skip to content

Commit c8896f4

Browse files
expose baseURL to cli commands
1 parent 20fc7e5 commit c8896f4

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

checks/runner.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
func CLIChecks(cliData api.CLIData, overrideBaseURL string, ch chan tea.Msg) (results []api.CLIStepResult) {
1616
client := &http.Client{}
17-
variables := make(map[string]string)
1817
results = make([]api.CLIStepResult, len(cliData.Steps))
1918

2019
if cliData.BaseURLDefault == api.BaseURLOverrideRequired && overrideBaseURL == "" {
@@ -25,6 +24,10 @@ func CLIChecks(cliData api.CLIData, overrideBaseURL string, ch chan tea.Msg) (re
2524
if overrideBaseURL == "" {
2625
baseURL = cliData.BaseURLDefault
2726
}
27+
variables := make(map[string]string)
28+
if baseURL != "" {
29+
variables["baseURL"] = baseURL
30+
}
2831

2932
for i, step := range cliData.Steps {
3033
// This is the magic of the initial message sent before executing the test

checks/runner_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,47 @@ import (
88
tea "github.com/charmbracelet/bubbletea"
99
)
1010

11+
func TestCLIChecksInterpolatesResolvedBaseURLInCommands(t *testing.T) {
12+
tests := []struct {
13+
name string
14+
defaultBaseURL string
15+
overrideBaseURL string
16+
want string
17+
}{
18+
{
19+
name: "manifest default",
20+
defaultBaseURL: "http://localhost:3000",
21+
want: "http://localhost:3000",
22+
},
23+
{
24+
name: "configured override",
25+
defaultBaseURL: "http://localhost:3000",
26+
overrideBaseURL: "http://localhost:4000",
27+
want: "http://localhost:4000",
28+
},
29+
}
30+
31+
for _, tt := range tests {
32+
t.Run(tt.name, func(t *testing.T) {
33+
cliData := api.CLIData{
34+
BaseURLDefault: tt.defaultBaseURL,
35+
Steps: []api.CLIStep{{
36+
CLICommand: &api.CLIStepCLICommand{
37+
Command: `printf '%s' '${baseURL}'`,
38+
},
39+
}},
40+
}
41+
messages := make(chan tea.Msg, 10)
42+
43+
results := CLIChecks(cliData, tt.overrideBaseURL, messages)
44+
45+
if got := results[0].CLICommandResult.Stdout; got != tt.want {
46+
t.Fatalf("command stdout = %q, want %q", got, tt.want)
47+
}
48+
})
49+
}
50+
}
51+
1152
func TestApplySubmissionResultsMarksAllStepsAndTestsPassedWhenNoFailure(t *testing.T) {
1253
cliData := api.CLIData{Steps: []api.CLIStep{
1354
{CLICommand: &api.CLIStepCLICommand{Tests: []api.CLICommandTest{{}, {}}}},

0 commit comments

Comments
 (0)