Skip to content

[test-improver] test(logger): add tests for generic global logger helpers#2277

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
test-improver/global-helpers-coverage-b7f3c0e6336d96e2
Draft

[test-improver] test(logger): add tests for generic global logger helpers#2277
github-actions[bot] wants to merge 1 commit intomainfrom
test-improver/global-helpers-coverage-b7f3c0e6336d96e2

Conversation

@github-actions
Copy link
Contributor

Summary

Adds internal/logger/global_helpers_test.go to directly test the generic helper functions withGlobalLogger, initGlobalLogger, and closeGlobalLogger that previously had no direct test coverage.

Tests Added (16 test functions)

withGlobalLogger

  • TestWithGlobalLogger_NilLogger_DoesNotInvokeCallback — nil logger → callback never called
  • TestWithGlobalLogger_NonNilLogger_InvokesCallback — non-nil logger → callback receives the logger
  • TestWithGlobalLogger_ConcurrentReads_NoRaceCondition — 20 concurrent goroutines, verifies no data race

initGlobalLogger

  • TestInitGlobalLogger_SetsNewLogger — stores new logger in the pointer
  • TestInitGlobalLogger_ReplacesExistingLogger — second call replaces first
  • TestInitGlobalLogger_SetsToNil — passing nil clears the global pointer
  • TestInitGlobalLogger_ClosesExistingFileLogger — old FileLogger's file is closed on replacement

closeGlobalLogger

  • TestCloseGlobalLogger_NilLogger_ReturnsNilError — nil pointer → returns nil, no panic
  • TestCloseGlobalLogger_NonNilLogger_ClosesAndClearsPointer — clears pointer after close
  • TestCloseGlobalLogger_FileLogger_PropagatesCloseError — pre-closed file → error propagated, pointer still cleared

Round-trip smoke tests (type-specific wrappers)

  • TestInitAndCloseGlobalFileLogger_RoundTrip
  • TestInitAndCloseGlobalJSONLLogger_RoundTrip
  • TestInitAndCloseGlobalMarkdownLogger_RoundTrip
  • TestInitAndCloseGlobalToolsLogger_RoundTrip
  • TestInitAndCloseGlobalServerFileLogger_RoundTrip

Integration

  • TestInitGlobalFileLogger_ReplacingExistingLogger — verifies that a second InitFileLogger call closes the first logger's file via the public API

Notes

  • All tests are package logger (white-box) to access unexported fields and globals
  • Struct literal alignment was corrected to match gofmt standards (logFile: file, with 5 spaces to align with useFallback:)
  • The go toolchain was unavailable for direct execution in this environment; CI will confirm compilation and test results

Generated by Test Improver ·

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants