Skip to content

Commit bdcd590

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

2 files changed

Lines changed: 50 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"] = strings.TrimSuffix(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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,52 @@ 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: "manifest default with trailing slash",
25+
defaultBaseURL: "http://localhost:3000/",
26+
want: "http://localhost:3000",
27+
},
28+
{
29+
name: "configured override",
30+
defaultBaseURL: "http://localhost:3000",
31+
overrideBaseURL: "http://localhost:4000/",
32+
want: "http://localhost:4000",
33+
},
34+
}
35+
36+
for _, tt := range tests {
37+
t.Run(tt.name, func(t *testing.T) {
38+
cliData := api.CLIData{
39+
BaseURLDefault: tt.defaultBaseURL,
40+
Steps: []api.CLIStep{{
41+
CLICommand: &api.CLIStepCLICommand{
42+
Command: `echo '${baseURL}'`,
43+
},
44+
}},
45+
}
46+
messages := make(chan tea.Msg, 10)
47+
48+
results := CLIChecks(cliData, tt.overrideBaseURL, messages)
49+
50+
if got := results[0].CLICommandResult.Stdout; got != tt.want {
51+
t.Fatalf("command stdout = %q, want %q", got, tt.want)
52+
}
53+
})
54+
}
55+
}
56+
1157
func TestApplySubmissionResultsMarksAllStepsAndTestsPassedWhenNoFailure(t *testing.T) {
1258
cliData := api.CLIData{Steps: []api.CLIStep{
1359
{CLICommand: &api.CLIStepCLICommand{Tests: []api.CLICommandTest{{}, {}}}},

0 commit comments

Comments
 (0)