test: add comprehensive tests, fuzz tests, and benchmarks#41
Conversation
Add 175 tests (up from ~12) covering all source files: - handler_test.go: handler lifecycle, concurrency, LogValuer resolution - formatter_test.go: adversarial edge cases, deep nesting, type/kind/key mismatches - formatter_pii_test.go: PII masking, ID preservation, boundary cases - formatter_http_test.go: request/response formatting, header visibility - formatter_time_test.go: time formats, unix timestamps, timezone conversion - formatter_error_test.go: error types, wrapping, nil errors - middleware_formatter_flatten_test.go: flatten helpers, middleware options Add 8 fuzz targets and 46 benchmark sub-cases. Add fuzz target to Makefile and CI workflow.
-fuzz=FuzzFormat matched multiple targets (FuzzFormatByKey, FuzzFormatByKind). Use $ anchor to match exact function names.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #41 +/- ##
===========================================
+ Coverage 29.77% 93.25% +63.48%
===========================================
Files 9 9
Lines 356 356
===========================================
+ Hits 106 332 +226
+ Misses 246 23 -223
+ Partials 4 1 -3
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 significantly expands the test suite for the slogformatter package by adding unit tests, fuzz targets, and benchmarks across the formatter, handler, and flattening middleware utilities, and wires fuzzing into local tooling and CI.
Changes:
- Add comprehensive unit tests for handler behavior, formatter edge cases, time/HTTP/error/PII formatters, and flattening helpers.
- Add multiple fuzz targets and a broad benchmark suite.
- Add a
make fuzztarget and run it in the GitHub Actions workflow.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
middleware_formatter_flatten_test.go |
Tests for flatten helpers and flatten middleware options/behavior |
handler_test.go |
Tests for handler lifecycle, groups/attrs behavior, LogValuer resolution, concurrency |
fuzz_test.go |
Adds fuzz targets for key/kind/type formatters and specific formatters (PII/time/error/IP/flatten) |
formatter_time_test.go |
Tests time formatting, unix timestamps, timezone conversion |
formatter_test.go |
Adds many edge-case tests for recursive formatting and matcher helpers |
formatter_pii_test.go |
Tests PII masking rules and ID preservation behavior |
formatter_http_test.go |
Tests request/response formatting and header hiding/showing |
formatter_error_test.go |
Tests error formatting including wrapping and nil handling |
benchmark_test.go |
Adds benchmarks covering formatter variants, nesting depth, and handler performance |
Makefile |
Adds fuzz target running all fuzzers |
.github/workflows/test.yml |
Runs fuzzing step in CI in addition to unit tests and coverage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- CI: restrict fuzz to single Go version (1.x) to reduce CI time - Makefile: add -run=^$ and ^ anchor to fuzz commands to skip unit tests and avoid ambiguous regex matches - handler_test: replace flaky WithinDuration time check with IsZero - flatten_test: rename DeepNested test to document known double-separator quirk; add Time and Group kinds to AllKinds test
- handler_test: check error return from h.Handle - flatten_test: use context.Background() instead of nil context - benchmark_test: remove unused newMockLogger function and imports
Add 175 tests (up from ~12) covering all source files:
Add 8 fuzz targets and 46 benchmark sub-cases.
Add fuzz target to Makefile and CI workflow.