Skip to content

test: add unit tests for WriteDebugger.Write in internal/iostreams - #871

Merged
mwbrooks merged 3 commits into
mainfrom
mwbrooks-test-write-debugger-write
Nov 27, 2026
Merged

mwbrooks merged 3 commits into
mainfrom
mwbrooks-test-write-debugger-write

Conversation

@mwbrooks

Copy link
Copy Markdown
Member

Changelog

N/A - adds tests only, with no user-facing changes.

Summary

This pull request adds unit tests for WriteDebugger.Write in internal/iostreams/writer.go, which had no test coverage. It is one in a series of small coverage PRs.

  • Adds Test_WriteDebugger_Write to internal/iostreams/writer_test.go with cases for one debug log per line, trimmed surrounding whitespace, and kept blank lines between lines
  • Raises internal/iostreams coverage from 59.4% to 63.8%

Testing

  1. Run go test ./internal/iostreams/... -run Test_WriteDebugger_Write -v and confirm the cases pass

Requirements

@mwbrooks
mwbrooks requested a review from a team as a code owner November 27, 2026 17:15
@mwbrooks mwbrooks added this to the Next Release milestone Nov 27, 2026
@mwbrooks mwbrooks added code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment labels Nov 27, 2026
@mwbrooks mwbrooks self-assigned this Nov 27, 2026
@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.95%. Comparing base (113ab0c) to head (3c0eaae).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #871      +/-   ##
==========================================
+ Coverage   80.93%   80.95%   +0.02%     
==========================================
  Files         247      247              
  Lines       18879    18879              
==========================================
+ Hits        15279    15283       +4     
+ Misses       3600     3596       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Thanks @mwbrooks! The trimmed-whitespace and kept-blank-line cases pin exactly the two quirks of WriteDebugger.Write that are easy to break.
Left one optional comment on asserting line order. 💯

Comment thread internal/iostreams/writer_test.go Outdated
Comment on lines +253 to +255
for _, line := range tc.expected {
ioMock.AssertCalled(t, "PrintDebug", ctx, "%s", []any{line})
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 suggestion (non-blocking): AssertCalled only checks each line was logged, so a writer that logs the lines in reverse still passes. Could we compare ioMock.Calls by index to pin the order too?

Suggested change
for _, line := range tc.expected {
ioMock.AssertCalled(t, "PrintDebug", ctx, "%s", []any{line})
}
for i, line := range tc.expected {
assert.Equal(t, mock.Arguments{ctx, "%s", []any{line}}, ioMock.Calls[i].Arguments)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 3bd2be7, great catch on the reverse order! 🙇

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 Thanks, the indexed check pins the order now: reversing the log order in Write fails two cases locally.

@mwbrooks

Copy link
Copy Markdown
Member Author

Thanks @WilliamBergamin for the thoughtful review! 🙇 The line order is now pinned in 3bd2be7. Would you mind a refresh review when you have a moment?

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Thanks @mwbrooks! With the order pinned, Test_WriteDebugger_Write now catches every way Write could mangle its lines.
Nothing left from me, ready to go 🚀

@mwbrooks

Copy link
Copy Markdown
Member Author

Thanks @WilliamBergamin for the thoughtful review and for checking the order catch locally! 🙇

@mwbrooks
mwbrooks merged commit 8c45bc1 into main Nov 27, 2026
14 checks passed
@mwbrooks
mwbrooks deleted the mwbrooks-test-write-debugger-write branch November 27, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants