Skip to content

test: add unit tests, benchmarks, and fuzz tests#36

Merged
samber merged 2 commits into
mainfrom
feat/more-tests
Mar 25, 2026
Merged

test: add unit tests, benchmarks, and fuzz tests#36
samber merged 2 commits into
mainfrom
feat/more-tests

Conversation

@samber
Copy link
Copy Markdown
Owner

@samber samber commented Mar 24, 2026

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.

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.
Copilot AI review requested due to automatic review settings March 24, 2026 19:11
@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 95.34%. Comparing base (56a9a78) to head (8c5ab96).
⚠️ Report is 1 commits behind head on main.

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

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

Comment thread attributes_test.go Outdated
Comment thread finder_test.go Outdated
Comment thread attributes_test.go
- 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
@samber samber merged commit 2da7764 into main Mar 25, 2026
9 checks passed
@samber samber deleted the feat/more-tests branch March 25, 2026 01:39
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