Skip to content

Commit 08c604e

Browse files
clean up jq logic
1 parent 0aef95a commit 08c604e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

checks/checks.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func formatJqExpectedValue(expected api.JqExpectedResult, variables map[string]s
289289
}
290290

291291
func collectStdoutJqOutputs(cmd api.CLIStepCLICommand, result api.CLICommandResult) []api.CLICommandJqOutput {
292-
outputs := make([]api.CLICommandJqOutput, 0)
292+
var outputs []api.CLICommandJqOutput
293293
for _, test := range cmd.Tests {
294294
if test.StdoutJq == nil {
295295
continue
@@ -319,8 +319,9 @@ func parseJqInput(stdout string, inputMode string) (any, error) {
319319
}
320320

321321
decoder := json.NewDecoder(strings.NewReader(stdout))
322+
decoder.UseNumber()
322323
if mode == "jsonl" {
323-
values := make([]any, 0)
324+
var values []any
324325
for {
325326
var value any
326327
err := decoder.Decode(&value)
@@ -339,7 +340,7 @@ func parseJqInput(stdout string, inputMode string) (any, error) {
339340
if err := decoder.Decode(&value); err != nil {
340341
return nil, err
341342
}
342-
if err := decoder.Decode(&struct{}{}); err != io.EOF {
343+
if err := decoder.Decode(&struct{}{}); !errors.Is(err, io.EOF) {
343344
if err == nil {
344345
return nil, errors.New("expected a single JSON value")
345346
}
@@ -355,14 +356,14 @@ func executeJqQuery(queryText string, input any) ([]any, error) {
355356
return nil, err
356357
}
357358
iter := query.Run(input)
358-
results := make([]any, 0)
359+
var results []any
359360
for {
360361
val, ok := iter.Next()
361362
if !ok {
362363
break
363364
}
364365
if err, ok := val.(error); ok {
365-
return results, err
366+
return nil, err
366367
}
367368
results = append(results, val)
368369
}

0 commit comments

Comments
 (0)