Skip to content

Commit 5f284b8

Browse files
committed
test: cover ErrorFormatter direct path in HandleExitCoder
Adds TestHandleExitCoder_ErrorFormatterDirect to exercise the Fprintf branch in HandleExitCoder when an ExitCoder also implements ErrorFormatter and is passed in directly. The existing TestHandleExitCoder_ErrorFormatter routes through a multiError which goes down a different branch, so the direct path was not hit by any test (codecov patch). Signed-off-by: alliasgher <alliasgher123@gmail.com>
1 parent 5200861 commit 5f284b8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

errors_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,23 @@ func TestHandleExitCoder_EmptyMessage(t *testing.T) {
257257
assert.True(t, called)
258258
assert.Empty(t, ErrWriter.(*bytes.Buffer).String(), "expected no output for empty-message exit")
259259
}
260+
261+
// TestHandleExitCoder_ErrorFormatterDirect verifies the ErrorFormatter branch
262+
// (Fprintf path) is exercised when the ExitCoder is passed to HandleExitCoder
263+
// directly with a non-empty message. Distinct from
264+
// TestHandleExitCoder_ErrorFormatter above which routes through a multiError.
265+
func TestHandleExitCoder_ErrorFormatterDirect(t *testing.T) {
266+
called := false
267+
OsExiter = func(rc int) { called = true }
268+
ErrWriter = &bytes.Buffer{}
269+
270+
defer func() {
271+
OsExiter = fakeOsExiter
272+
ErrWriter = fakeErrWriter
273+
}()
274+
275+
HandleExitCoder(&exitFormatter{code: 7})
276+
277+
assert.True(t, called)
278+
assert.Contains(t, ErrWriter.(*bytes.Buffer).String(), "some other special")
279+
}

0 commit comments

Comments
 (0)