Skip to content

test: add comprehensive tests, fuzz tests, and benchmarks#41

Merged
samber merged 4 commits into
mainfrom
feat/comprehensive-tests
Mar 24, 2026
Merged

test: add comprehensive tests, fuzz tests, and benchmarks#41
samber merged 4 commits into
mainfrom
feat/comprehensive-tests

Conversation

@samber
Copy link
Copy Markdown
Owner

@samber samber commented Mar 24, 2026

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.

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.
Copilot AI review requested due to automatic review settings March 24, 2026 17:58
-fuzz=FuzzFormat matched multiple targets (FuzzFormatByKey, FuzzFormatByKind).
Use $ anchor to match exact function names.
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.25%. Comparing base (70ac23d) to head (5107993).
⚠️ Report is 1 commits behind head on main.

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     
Flag Coverage Δ
unittests 93.25% <ø> (+63.48%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 fuzz target 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.

Comment thread .github/workflows/test.yml
Comment thread middleware_formatter_flatten_test.go
Comment thread middleware_formatter_flatten_test.go
Comment thread handler_test.go
Comment thread Makefile Outdated
samber added 2 commits March 24, 2026 19:14
- 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
@samber samber merged commit aada1c9 into main Mar 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants