Skip to content

Commit 4f27c89

Browse files
committed
integration: Create helpers to parse multiple JSON array output
Signed-off-by: Jose Blanquicet <[email protected]>
1 parent 79eb655 commit 4f27c89

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

integration/run_helpers.go

+28
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package integration
1616

1717
import (
18+
"bufio"
1819
"encoding/json"
1920
"fmt"
2021
"reflect"
@@ -186,9 +187,36 @@ func parseJSONArrayOutputToObj(t *testing.T, output string, normalize func(map[s
186187
return ret
187188
}
188189

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+
189205
// ExpectEntriesInArrayToMatchObj verifies that all the entries in expectedEntries are
190206
// matched by at least one entry in the output (JSON array of JSON objects).
191207
func ExpectEntriesInArrayToMatchObj(t *testing.T, output string, normalize func(map[string]interface{}), expectedEntries ...map[string]interface{}) {
192208
entries := parseJSONArrayOutputToObj(t, output, normalize)
193209
expectEntriesToMatchObj(t, entries, expectedEntries...)
194210
}
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

Comments
 (0)