[test] Add tests for logger error paths: MarkdownLogger.Close, FileLogger.Log, Logger.Print#6647
Merged
lpcox merged 4 commits intoMay 29, 2026
Conversation
Cover previously untested error-handling branches in the logger package: - MarkdownLogger.Close: footer WriteString error path (was 85.7%, now 100%) - MarkdownLogger.initializeFile: header WriteString error path (was 87.5%, now 100%) - MarkdownLogger.Log: body WriteString error path, nil logFile path (was 92.3%, now 96.2%) - FileLogger.Log: Sync error warning path (was 85.7%, now 100%) - Logger.Print: disabled logger early-return path (was 91.7%, now 100%) All error paths are triggered by closing the underlying *os.File before calling the respective function, which causes file operations to return os.ErrClosed. This approach avoids complex mocking while testing real error-handling code paths. Overall logger package coverage: 97.6% → 98.6% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves internal/logger test coverage by adding white-box tests for logger error-handling and disabled-output paths without changing production code.
Changes:
- Adds tests for
MarkdownLogger.Close,initializeFile, andLogfallback/error branches. - Adds coverage for
FileLogger.Logsync-error handling. - Adds coverage for
Logger.Printwhen disabled by an emptyDEBUGsetting.
Show a summary per file
| File | Description |
|---|---|
internal/logger/markdown_logger_close_coverage_test.go |
Adds focused logger coverage tests for markdown, file, and debug logger error/disabled paths. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Collaborator
|
@copilot fix the failing lint ci check |
Contributor
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: logger error-handling paths
Functions Analyzed
MarkdownLogger.Closeinternal/loggerMarkdownLogger.initializeFileinternal/loggerFileLogger.Loginternal/loggerLogger.Printinternal/loggerMarkdownLogger.Loginternal/loggerOverall logger package: 97.6% → 98.6%
Why These Functions?
Five related functions in
internal/loggerhad the lowest coverage in the buildable package set, all with untested error-handling branches:MarkdownLogger.Close(85.7%) — the footerWriteStringerror path was never exercised; the implementation correctly falls through tocloseLogFileeven when the footer write failsMarkdownLogger.initializeFile(87.5%) — the headerWriteStringerror path; the function should return the error and leaveml.initialized = falseFileLogger.Log(85.7%) — theSync()error path; aWARNING: Failed to sync log filemessage should be emitted to stderrLogger.Print(91.7%) — the disabled-logger early-return branch; callingPrinton a logger with noDEBUGmatch was never testedTests Added
TestMarkdownLogger_Close_FooterWriteError— triggers footer write failure by pre-closing the underlying*os.FileTestMarkdownLogger_Close_NilLogFile— exercises thelogFile == nilbranch (fallback/no-file mode)TestMarkdownLogger_InitializeFile_WriteError— triggers header write failure via closed fileTestMarkdownLogger_InitializeFile_AlreadyInitialized— fast-path no-op when already initializedTestMarkdownLogger_Log_WriteError— body write failure after successful header initTestMarkdownLogger_Log_NilLogFile— silent drop whenlogFileis nilTestFileLogger_Log_SyncError— sync warning path via closed fileTestLogger_Print_Disabled— early return when logger is disabledTechnique
All error paths are triggered by closing the underlying
*os.Filebefore calling the function, causing subsequent OS operations to returnos.ErrClosed. Tests are inpackage logger(white-box) to allow direct struct construction and field access without requiring additional exported helpers.Coverage Report
Test Execution
All 8 new tests pass:
Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
Firewall blocked 6 domains
The following domains were blocked by the firewall during workflow execution:
go.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inproxy.golang.orgSee Network Configuration for more information.