Repository navigation
test: add unit tests for WriteDebugger.Write in internal/iostreams - #871
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
WilliamBergamin
left a comment
There was a problem hiding this comment.
🧪 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. 💯
| for _, line := range tc.expected { | ||
| ioMock.AssertCalled(t, "PrintDebug", ctx, "%s", []any{line}) | ||
| } |
There was a problem hiding this comment.
🧪 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?
| 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) | |
| } |
There was a problem hiding this comment.
Fixed in commit 3bd2be7, great catch on the reverse order! 🙇
There was a problem hiding this comment.
💯 Thanks, the indexed check pins the order now: reversing the log order in Write fails two cases locally.
|
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
left a comment
There was a problem hiding this comment.
🧪 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 🚀
|
Thanks @WilliamBergamin for the thoughtful review and for checking the order catch locally! 🙇 |
Changelog
N/A - adds tests only, with no user-facing changes.
Summary
This pull request adds unit tests for
WriteDebugger.Writeininternal/iostreams/writer.go, which had no test coverage. It is one in a series of small coverage PRs.Test_WriteDebugger_Writetointernal/iostreams/writer_test.gowith cases for one debug log per line, trimmed surrounding whitespace, and kept blank lines between linesinternal/iostreamscoverage from 59.4% to 63.8%Testing
go test ./internal/iostreams/... -run Test_WriteDebugger_Write -vand confirm the cases passRequirements