[test] Add tests for logger fallback init helper functions#10122
[test] Add tests for logger fallback init helper functions#10122github-actions[bot] wants to merge 3 commits into
Conversation
Add direct unit tests for four package-private helpers in internal/logger/global_helpers.go that had no direct test coverage: - logFallbackWarnings: verify two WARNING lines are printed with the expected error message and fallback description - fallbackLoggerOnInitError: verify warnings are emitted and the fallback value is returned with nil error; covers pointer types - silentFallbackLoggerOnInitError: verify the fallback is returned with nil error and no log output is produced; covers nil pointers - strictLoggerOnInitError: verify the original error is propagated and the zero value is returned; covers pointer and scalar types All tests are table-driven or scenario-based, use captureStdLog for stderr capture, and follow the testify patterns established by the rest of the logger package. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds direct unit coverage for logger initialization fallback helpers.
Changes:
- Tests warning output and fallback behavior.
- Covers generic value, pointer, nil, and strict error paths.
Show a summary per file
| File | Description |
|---|---|
internal/logger/fallback_init_helpers_test.go |
Adds focused tests for logger fallback helpers. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Medium
This comment has been minimized.
This comment has been minimized.
🔒 mcpg Read-Only Stress — docker-sbxSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Notes:
Overall: PASS References: §30211555467
|
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Gateway allowlist: 22 read-only tools; all write tools absent. Write attempt error: Overall: PASS References: §30211555480
|
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>
🔒 mcpg Read-Only Stress — gVisorSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Part B enforcement: All 7 write tools refused with gateway MCP error Overall: PASS References: §30220686705
|
Test Coverage Improvement: logger fallback init helpers
Functions Analyzed
internal/loggerlogFallbackWarningsfallbackLoggerOnInitErrorsilentFallbackLoggerOnInitErrorstrictLoggerOnInitErrorInit*functions)Why These Functions?
These four helper functions in
internal/logger/global_helpers.goimplement the three logger error-handling strategies used across the entire logger package:fallbackLoggerOnInitErrorFileLogger,ToolsLogger,ObservedURLDomainsLogger,ServerFileLoggersilentFallbackLoggerOnInitErrorMarkdownLoggerstrictLoggerOnInitErrorJSONLLoggerlogFallbackWarningsfallbackLoggerOnInitErrorDespite being invoked by every logger init path, none of them had a direct test. They're independently testable and have clear behavioral contracts.
Tests Added
TestLogFallbackWarnings— verifies twoWARNING:lines are emittedTestLogFallbackWarnings_ErrorMessageInFirstLine— verifies line ordering (error first, fallback second)TestFallbackLoggerOnInitError_ReturnsProvidedFallback— verifies error is swallowed and fallback returnedTestFallbackLoggerOnInitError_LogsWarnings— verifies warning side-effects are emittedTestFallbackLoggerOnInitError_PointerType— covers generic pointer usage matching realfile_logger.gocallsiteTestSilentFallbackLoggerOnInitError_ReturnsProvidedFallback— verifies silent return with no log outputTestSilentFallbackLoggerOnInitError_NilPointer— covers nil pointer fallback (matchingMarkdownLoggerusage)TestStrictLoggerOnInitError_PropagatesError— verifies error is returned unchanged and zero value is returnedTestStrictLoggerOnInitError_NilErrorStillReturnsZero— verifies zero value returned even for nil errorTestStrictLoggerOnInitError_PointerType— covers generic pointer usage matchingJSONLLoggercallsiteCoverage Improvement
Test Execution
Tests are designed to pass in CI (where module dependencies are available). The test file:
captureStdLoghelper already established instartup_test.gopackage logger(white-box) convention used by all other logger testsassert/requireas per project standardsGenerated 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.