Skip to content

Commit

Permalink
small improvement to TestScanOutput_WithNonJSONLines
Browse files Browse the repository at this point in the history
Use t.Run to separate the cases, use DeepEqual to check the slices removing the need for a
separate length check, and wrap a line to make the linter happy.
  • Loading branch information
dnephin committed May 15, 2021
1 parent 226f339 commit 4710cc6
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions testjson/execution_test.go
Expand Up @@ -212,21 +212,24 @@ func TestScanOutput_WithNonJSONLines(t *testing.T) {
// Test that when we ignore non-JSON lines, scanning completes, and test
// that when we don't ignore non-JSON lines, scanning fails.
for _, ignore := range []bool{true, false} {
handler := &captureHandler{}
cfg := ScanConfig{
Stdout: bytes.NewReader(source),
Handler: handler,
IgnoreNonJSONOutputLines: ignore,
}
_, err := ScanTestOutput(cfg)
if ignore {
assert.Assert(t, len(handler.errs) == 1)
assert.Assert(t, handler.errs[0] == nonJSONLine)
assert.NilError(t, err)
} else {
assert.Assert(t, len(handler.errs) == 0)
assert.Error(t, err, "failed to parse test output: "+nonJSONLine+": invalid character '|' looking for beginning of value")
}
t.Run(fmt.Sprintf("ignore-non-json=%v", ignore), func(t *testing.T) {
handler := &captureHandler{}
cfg := ScanConfig{
Stdout: bytes.NewReader(source),
Handler: handler,
IgnoreNonJSONOutputLines: ignore,
}
_, err := ScanTestOutput(cfg)
if ignore {
assert.DeepEqual(t, handler.errs, []string{nonJSONLine})
assert.NilError(t, err)
return
}
assert.DeepEqual(t, handler.errs, []string{}, cmpopts.EquateEmpty())
expected := "failed to parse test output: " +
nonJSONLine + ": invalid character '|' looking for beginning of value"
assert.Error(t, err, expected)
})
}
}

Expand Down

0 comments on commit 4710cc6

Please sign in to comment.