[test] Add tests for logger.SlogHandler.Handle and related functions#3381
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test] Add tests for logger.SlogHandler.Handle and related functions#3381github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
- Add TestSlogHandler_Handle_WithDebugEnabled: covers all 4 log level
prefixes (DEBUG/INFO/WARN/ERROR) and unknown level fallback
- Add TestSlogHandler_Handle_WhenDisabled: verifies early return when
logger is not enabled
- Add TestSlogHandler_Handle_WithAttributes: covers all attribute types
(string, int, bool, float) and multiple/empty attribute cases
- Add TestFormatSlogValue: covers both slog.Value and non-slog.Value
inputs including nil, integer, boolean, and string
- Add TestNewSlogLoggerWithHandler_Enabled/Disabled/MultipleMessages:
covers NewSlogLoggerWithHandler with enabled and disabled loggers
- Add TestSlogHandler_Handle_AllLevelPrefixes: targeted table-driven
test for all 4 standard slog level prefix cases
Tests use t.Setenv("DEBUG", "*") instead of t.Skip() so they run
in all environments, bringing Handle from 0% → 95.2%, formatSlogValue
from 0% → 100%, and NewSlogLoggerWithHandler from 0% → 100%.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test Coverage Improvement:
slog_adapter.goFunction Analyzed
internal/loggerSlogHandler.Handle,formatSlogValue,NewSlogLoggerWithHandlerHandle→ 95.2%,formatSlogValue→ 100%,NewSlogLoggerWithHandler→ 100%Why These Functions?
These three functions in
internal/logger/slog_adapter.gohad 0% coverage because all existing tests guarded execution with:Generated by Test Coverage Improver
Next run will target the next most complex under-tested function