| 70 | } |
| 71 | |
| 72 | func availableVariablesForHTTPResult(result api.HTTPRequestResult) (entries []variableEntry, expectsVariables bool) { |
| 73 | seen := map[string]bool{} |
| 74 | |
| 75 | add := func(name, description string) { |
| 76 | if name == "baseURL" { |
| 77 | return |
| 78 | } |
| 79 | expectsVariables = true |
| 80 | value := result.Variables[name] |
| 81 | key := name + "\x00" + description |
| 82 | if seen[key] { |
| 83 | return |
| 84 | } |
| 85 | seen[key] = true |
| 86 | entries = append(entries, variableEntry{ |
| 87 | name: name, |
| 88 | value: value, |
| 89 | description: description, |
| 90 | }) |
| 91 | } |
| 92 | |
| 93 | addInterpolationNames := func(value, description string) { |
| 94 | for _, name := range checks.InterpolationNames(value) { |
| 95 | add(name, description) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | addInterpolationNames(result.Request.Request.FullURL, "Request URL") |
| 100 | for key, value := range result.Request.Request.Headers { |
| 101 | addInterpolationNames(value, fmt.Sprintf("Request Header %q", key)) |
| 102 | } |
| 103 | for key, value := range result.Request.Request.BodyForm { |
| 104 | addInterpolationNames(value, fmt.Sprintf("Request Form Field %q", key)) |
| 105 | } |
| 106 | if result.Request.Request.BodyJSON != nil { |
| 107 | if body, err := json.Marshal(result.Request.Request.BodyJSON); err == nil { |
| 108 | addInterpolationNames(string(body), "Request JSON Body") |
| 109 | } |
| 110 | } |
| 111 | for _, test := range result.Request.Tests { |
| 112 | if test.BodyContains != nil { |
| 113 | addInterpolationNames(*test.BodyContains, "Body Contains Test") |
| 114 | } |
| 115 | if test.BodyContainsNone != nil { |
| 116 | addInterpolationNames(*test.BodyContainsNone, "Body Excludes Test") |
| 117 | } |
| 118 | if test.HeadersContain != nil { |
| 119 | addInterpolationNames(test.HeadersContain.Key, "Header Test Key") |
| 120 | addInterpolationNames(test.HeadersContain.Value, "Header Test Value") |
| 121 | } |
| 122 | if test.TrailersContain != nil { |
| 123 | addInterpolationNames(test.TrailersContain.Key, "Trailer Test Key") |
| 124 | addInterpolationNames(test.TrailersContain.Value, "Trailer Test Value") |
| 125 | } |
| 126 | if test.JSONValue != nil && test.JSONValue.StringValue != nil { |
| 127 | addInterpolationNames(*test.JSONValue.StringValue, "JSON Value Test") |
| 128 | } |
| 129 | } |