test: add unit tests, benchmarks, and fuzz tests#36
Conversation
Coverage improved from 62% to 97%. Added tests for untested functions (AttrToValue, AttrsToString, ReplaceError, FormatErrorKey, FormatRequest, StringSource, RecordToAttrsMap, FindAttrByKey, FindAttrByGroupAndKey, ExtractFromContext, UniqAttrs), benchmarks for all key functions, and 7 fuzz tests for panic prevention. Added make fuzz target and CI fuzz step for Go 1.21.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #36 +/- ##
===========================================
+ Coverage 56.97% 95.34% +38.37%
===========================================
Files 4 4
Lines 258 258
===========================================
+ Hits 147 246 +99
+ Misses 108 10 -98
+ Partials 3 2 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR expands the slogcommon Go package’s test suite by adding unit tests, benchmarks, and fuzz tests, and wires fuzzing into local tooling and CI to improve confidence and prevent panics.
Changes:
- Added unit tests for previously untested helpers (including
UniqAttrs, finder helpers, and context extraction). - Added benchmarks for key functions to track allocations/performance over time.
- Added fuzz tests plus
make fuzzand a CI fuzz step (Go 1.21) to harden against panics.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| groups_test.go | Adds unit tests for UniqAttrs. |
| fuzz_test.go | Adds fuzz tests to exercise common APIs for panic prevention. |
| finder_test.go | Adds tests for FindAttrByKey / FindAttrByGroupAndKey (currently includes a case documenting buggy behavior). |
| context_test.go | Adds unit tests for ExtractFromContext. |
| benchmark_test.go | Adds benchmarks for major functions (AttrsToMap, ReplaceAttrs, UniqAttrs, FormatRequest, etc.). |
| attributes_test.go | Adds multiple new unit tests; updates TestSource expected line number due to import shifts. |
| Makefile | Adds a fuzz target running each fuzz test for a short duration. |
| .github/workflows/test.yml | Adds CI fuzz step (Go 1.21 only) and disables matrix fail-fast. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- TestSource: derive expected line number from runtime.Caller instead of hardcoding it - TestRecordToAttrsMap: add commented-out regression guards for the known bug - FindAttrByGroupAndKey test: clarify comment about expected behavior after bug fix
Coverage improved from 62% to 97%. Added tests for untested functions
(AttrToValue, AttrsToString, ReplaceError, FormatErrorKey, FormatRequest,
StringSource, RecordToAttrsMap, FindAttrByKey, FindAttrByGroupAndKey,
ExtractFromContext, UniqAttrs), benchmarks for all key functions, and
7 fuzz tests for panic prevention. Added make fuzz target and CI fuzz
step for Go 1.21.