|
15 | 15 | package integration
|
16 | 16 |
|
17 | 17 | import (
|
| 18 | + "bufio" |
18 | 19 | "encoding/json"
|
19 | 20 | "fmt"
|
20 | 21 | "reflect"
|
@@ -186,9 +187,36 @@ func parseJSONArrayOutputToObj(t *testing.T, output string, normalize func(map[s
|
186 | 187 | return ret
|
187 | 188 | }
|
188 | 189 |
|
| 190 | +func parseMultipleJSONArrayOutputToObj(t *testing.T, output string, normalize func(map[string]interface{})) []map[string]interface{} { |
| 191 | + ret := []map[string]interface{}{} |
| 192 | + |
| 193 | + sc := bufio.NewScanner(strings.NewReader(output)) |
| 194 | + // On ARO we saw arrays with charcounts of > 100,000. Lets just set 1 MB as the limit |
| 195 | + sc.Buffer(make([]byte, 1024), 1024*1024) |
| 196 | + for sc.Scan() { |
| 197 | + entries := parseJSONArrayOutputToObj(t, sc.Text(), normalize) |
| 198 | + ret = append(ret, entries...) |
| 199 | + } |
| 200 | + require.NoError(t, sc.Err(), "parsing multiple JSON arrays") |
| 201 | + |
| 202 | + return ret |
| 203 | +} |
| 204 | + |
189 | 205 | // ExpectEntriesInArrayToMatchObj verifies that all the entries in expectedEntries are
|
190 | 206 | // matched by at least one entry in the output (JSON array of JSON objects).
|
191 | 207 | func ExpectEntriesInArrayToMatchObj(t *testing.T, output string, normalize func(map[string]interface{}), expectedEntries ...map[string]interface{}) {
|
192 | 208 | entries := parseJSONArrayOutputToObj(t, output, normalize)
|
193 | 209 | expectEntriesToMatchObj(t, entries, expectedEntries...)
|
194 | 210 | }
|
| 211 | + |
| 212 | +// ExpectEntriesInMultipleArrayToMatchObj verifies that all the entries in expectedEntries are |
| 213 | +// matched by at least one entry in the output (multiple JSON array of JSON objects separated by newlines). |
| 214 | +func ExpectEntriesInMultipleArrayToMatchObj( |
| 215 | + t *testing.T, |
| 216 | + output string, |
| 217 | + normalize func(map[string]interface{}), |
| 218 | + expectedEntries ...map[string]interface{}, |
| 219 | +) { |
| 220 | + entries := parseMultipleJSONArrayOutputToObj(t, output, normalize) |
| 221 | + expectEntriesToMatchObj(t, entries, expectedEntries...) |
| 222 | +} |
0 commit comments