[test-improver] test(logger): add tests for generic global logger helpers#2277
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test-improver] test(logger): add tests for generic global logger helpers#2277github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Add global_helpers_test.go to directly test the generic helper functions withGlobalLogger, initGlobalLogger, and closeGlobalLogger which previously had no direct test coverage. Tests added: - TestWithGlobalLogger: nil-logger (no callback), non-nil logger (callback invoked), concurrent read safety - TestInitGlobalLogger: sets new logger, replaces existing logger (closes old), sets to nil, closes existing FileLogger on replacement - TestCloseGlobalLogger: nil logger returns nil, non-nil logger cleared, FileLogger close error propagated - Round-trip smoke tests for all five type-specific wrappers (FileLogger, JSONLLogger, MarkdownLogger, ServerFileLogger, ToolsLogger) - Integration test for FileLogger replacement via public InitFileLogger API Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7 tasks
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.
Summary
Adds
internal/logger/global_helpers_test.goto directly test the generic helper functionswithGlobalLogger,initGlobalLogger, andcloseGlobalLoggerthat previously had no direct test coverage.Tests Added (16 test functions)
withGlobalLoggerTestWithGlobalLogger_NilLogger_DoesNotInvokeCallback— nil logger → callback never calledTestWithGlobalLogger_NonNilLogger_InvokesCallback— non-nil logger → callback receives the loggerTestWithGlobalLogger_ConcurrentReads_NoRaceCondition— 20 concurrent goroutines, verifies no data raceinitGlobalLoggerTestInitGlobalLogger_SetsNewLogger— stores new logger in the pointerTestInitGlobalLogger_ReplacesExistingLogger— second call replaces firstTestInitGlobalLogger_SetsToNil— passing nil clears the global pointerTestInitGlobalLogger_ClosesExistingFileLogger— old FileLogger's file is closed on replacementcloseGlobalLoggerTestCloseGlobalLogger_NilLogger_ReturnsNilError— nil pointer → returns nil, no panicTestCloseGlobalLogger_NonNilLogger_ClosesAndClearsPointer— clears pointer after closeTestCloseGlobalLogger_FileLogger_PropagatesCloseError— pre-closed file → error propagated, pointer still clearedRound-trip smoke tests (type-specific wrappers)
TestInitAndCloseGlobalFileLogger_RoundTripTestInitAndCloseGlobalJSONLLogger_RoundTripTestInitAndCloseGlobalMarkdownLogger_RoundTripTestInitAndCloseGlobalToolsLogger_RoundTripTestInitAndCloseGlobalServerFileLogger_RoundTripIntegration
TestInitGlobalFileLogger_ReplacingExistingLogger— verifies that a secondInitFileLoggercall closes the first logger's file via the public APINotes
package logger(white-box) to access unexported fields and globalslogFile: file,with 5 spaces to align withuseFallback:)