From 4710cc6a3267fdc718a544c5dd38b9eb683c6757 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Sat, 15 May 2021 16:12:38 -0400 Subject: [PATCH] small improvement to TestScanOutput_WithNonJSONLines 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. --- testjson/execution_test.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/testjson/execution_test.go b/testjson/execution_test.go index 731dd107..281a3dc8 100644 --- a/testjson/execution_test.go +++ b/testjson/execution_test.go @@ -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) + }) } }