| 132 | } |
| 133 | |
| 134 | func availableVariablesForCLIResult(result api.CLICommandResult) (entries []variableEntry, expectsVariables bool) { |
| 135 | seen := map[string]bool{} |
| 136 | |
| 137 | add := func(name, description string) { |
| 138 | expectsVariables = true |
| 139 | value := result.Variables[name] |
| 140 | key := name + "\x00" + description |
| 141 | if seen[key] { |
| 142 | return |
| 143 | } |
| 144 | seen[key] = true |
| 145 | entries = append(entries, variableEntry{ |
| 146 | name: name, |
| 147 | value: value, |
| 148 | description: description, |
| 149 | }) |
| 150 | } |
| 151 | |
| 152 | addInterpolationNames := func(value, description string) { |
| 153 | for _, name := range checks.InterpolationNames(value) { |
| 154 | add(name, description) |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | addInterpolationNames(result.Command.Command, "Command") |
| 159 | for _, test := range result.Command.Tests { |
| 160 | for _, contains := range test.StdoutContainsAll { |
| 161 | addInterpolationNames(contains, "Stdout Contains Test") |
| 162 | } |
| 163 | for _, contains := range test.StdoutContainsNone { |
| 164 | addInterpolationNames(contains, "Stdout Excludes Test") |
| 165 | } |
| 166 | if test.StdoutJq != nil { |
| 167 | addInterpolationNames(test.StdoutJq.Query, "JQ Query") |
| 168 | for _, expected := range test.StdoutJq.ExpectedResults { |
| 169 | if expected.Type != api.JqTypeString { |
| 170 | continue |
| 171 | } |
| 172 | if value, ok := expected.Value.(string); ok { |
| 173 | addInterpolationNames(value, "JQ Expected Value") |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | return entries, expectsVariables |
| 180 | } |