MCPcopy Index your code
hub / github.com/bootdotdev/bootdev / CLIChecks

Function CLIChecks

checks/runner.go:15–73  ·  view source on GitHub ↗
(cliData api.CLIData, overrideBaseURL string, ch chan tea.Msg)

Source from the content-addressed store, hash-verified

13)
14
15func CLIChecks(cliData api.CLIData, overrideBaseURL string, ch chan tea.Msg) (results []api.CLIStepResult) {
16 client := &http.Client{}
17 variables := make(map[string]string)
18 results = make([]api.CLIStepResult, len(cliData.Steps))
19
20 if cliData.BaseURLDefault == api.BaseURLOverrideRequired && overrideBaseURL == "" {
21 cobra.CheckErr("lesson requires a base URL override: `bootdev configure base_url <url>`")
22 }
23
24 baseURL := overrideBaseURL
25 if overrideBaseURL == "" {
26 baseURL = cliData.BaseURLDefault
27 }
28
29 for i, step := range cliData.Steps {
30 // This is the magic of the initial message sent before executing the test
31 if step.CLICommand != nil {
32 ch <- messages.StartStepMsg{
33 CMD: step.CLICommand.Command,
34 TmdlQuery: step.CLICommand.StdoutFilterTmdl,
35 NoPenaltyOnFail: step.NoPenaltyOnFail,
36 }
37 } else if step.HTTPRequest != nil {
38 finalBaseURL := baseURL
39 overrideURL := viper.GetString("override_base_url")
40 if overrideURL != "" {
41 finalBaseURL = overrideURL
42 }
43 fullURL := strings.Replace(step.HTTPRequest.Request.FullURL, api.BaseURLPlaceholder, finalBaseURL, 1)
44 interpolatedURL := InterpolateVariables(fullURL, variables)
45
46 ch <- messages.StartStepMsg{
47 URL: interpolatedURL,
48 Method: step.HTTPRequest.Request.Method,
49 NoPenaltyOnFail: step.NoPenaltyOnFail,
50 }
51 }
52
53 switch {
54 case step.CLICommand != nil:
55 result := runCLICommand(*step.CLICommand, variables)
56 result.JqOutputs = collectStdoutJqOutputs(*step.CLICommand, result)
57 results[i].CLICommandResult = &result
58
59 sendCLICommandResults(ch, *step.CLICommand, result, i)
60 handleSleep(step.CLICommand, ch)
61
62 case step.HTTPRequest != nil:
63 result := runHTTPRequest(client, baseURL, variables, *step.HTTPRequest)
64 results[i].HTTPRequestResult = &result
65 sendHTTPRequestResults(ch, *step.HTTPRequest, result, i)
66 handleSleep(step.HTTPRequest, ch)
67
68 default:
69 cobra.CheckErr("unable to run lesson: missing step")
70 }
71 }
72 return results

Callers 1

submissionHandlerFunction · 0.92

Calls 7

InterpolateVariablesFunction · 0.85
runCLICommandFunction · 0.85
collectStdoutJqOutputsFunction · 0.85
sendCLICommandResultsFunction · 0.85
handleSleepFunction · 0.85
runHTTPRequestFunction · 0.85
sendHTTPRequestResultsFunction · 0.85

Tested by

no test coverage detected