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

Function TestHTTPVariableSections

render/variables_test.go:10–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestHTTPVariableSections(t *testing.T) {
11 result := api.HTTPRequestResult{
12 Variables: map[string]string{
13 "authToken": "token-123",
14 "shortCode": "abc123",
15 },
16 Request: api.CLIStepHTTPRequest{
17 ResponseVariables: []api.HTTPRequestResponseVariable{
18 {Name: "shortCode", Path: ".short_code"},
19 {Name: "missingCode", Path: ".missing_code"},
20 },
21 Request: api.HTTPRequest{
22 FullURL: "${baseURL}/api/links/${shortCode}",
23 Headers: map[string]string{
24 "Authorization": "Bearer ${authToken}",
25 },
26 },
27 },
28 }
29
30 got := renderVariableSection("Variables Saved", savedVariablesForHTTPResult(result))
31 got += renderVariableSection("Variables Missing", missingSaveVariablesForHTTPResult(result))
32 available, expectsVariables := availableVariablesForHTTPResult(result)
33 if !expectsVariables {
34 t.Fatalf("expected HTTP request to use variables")
35 }
36 got += renderVariableSection("Variables Available", available)
37
38 wantContains := []string{
39 "Variables Saved:",
40 "shortCode: abc123 (JSON Body .short_code)",
41 "Variables Missing:",
42 "missingCode: [not found] (JSON Body .missing_code)",
43 "Variables Available:",
44 "authToken: token-123 (Request Header \"Authorization\")",
45 "shortCode: abc123 (Request URL)",
46 }
47
48 for _, want := range wantContains {
49 if !strings.Contains(got, want) {
50 t.Fatalf("expected %q in:\n%s", want, got)
51 }
52 }
53 if strings.Contains(got, "baseURL") {
54 t.Fatalf("did not expect special baseURL placeholder in:\n%s", got)
55 }
56}
57
58func TestAvailableVariablesPrintsNotFoundWhenExpectedButUnavailable(t *testing.T) {
59 result := api.CLICommandResult{

Callers

nothing calls this directly

Tested by

no test coverage detected