Skip to content

Restore global logger state in tests - #211

Merged
jeffwidman merged 1 commit into
mainfrom
restore-test-logger-state
Aug 18, 2026
Merged

Restore global logger state in tests#211
jeffwidman merged 1 commit into
mainfrom
restore-test-logger-state

Conversation

@jeffwidman

@jeffwidman jeffwidman commented Aug 17, 2026

Copy link
Copy Markdown
Member

Summary

Tests in several packages redirect the process-wide standard logger to capture output. Most did not restore the previous writer, so later tests could inherit a buffer owned by an earlier test. One OIDC registry test restored os.Stderr rather than the actual previous writer. TestSetupLogging also exercised production code that changes both standard-log and Logrus global configuration without restoring either logger.

This change adds shared test helpers that snapshot and restore:

  • standard logger output, flags, and prefix
  • Logrus output, formatter, level, and caller-reporting state

All direct output captures now use those helpers, and TestSetupLogging preserves state before invoking production setup. A focused helper test mutates every captured field in a subtest and verifies that cleanup restores the exact prior state.

The branch was rebased onto current main. During the audit of changes merged since the PR was opened, one additional NuGet test logger capture was found and migrated to the helper. No other uncovered global logger mutations remain in tests.

This does not make process-wide logger mutation safe for parallel tests. These tests should continue to run serially; the change prevents state from leaking after each test or subtest completes.

Validation

go test -race ./... -count=1

All packages pass.

Base automatically changed from defer-nuget-service-index-discovery to main August 18, 2026 16:31
@jeffwidman
jeffwidman force-pushed the restore-test-logger-state branch from 5af0a61 to b410d62 Compare August 18, 2026 22:29
@jeffwidman
jeffwidman marked this pull request as ready for review August 18, 2026 22:29
@jeffwidman
jeffwidman requested a review from a team as a code owner August 18, 2026 22:29
Copilot AI balanced review requested due to automatic review settings August 18, 2026 22:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds shared test helpers to prevent process-wide logger state from leaking between serial tests.

Changes:

  • Snapshot and restore standard-log and Logrus configuration.
  • Migrate all logger-capturing tests to shared helpers.
  • Verify restoration of every captured logger field.
Show a summary per file
File Description
proxy_test.go Uses combined logger capture helper.
logging_test.go Preserves logger state around logging tests.
internal/testhelpers/logging.go Adds logger preservation and capture helpers.
internal/testhelpers/logging_test.go Tests complete state restoration.
internal/oidc/oidc_registry_test.go Restores the actual previous log writer.
internal/logging/logging_test.go Uses standard-log capture helper.
internal/handlers/oidc_handling_test.go Prevents OIDC test log leakage.
internal/handlers/nuget_feed_test.go Prevents NuGet test log leakage.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 8/8 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@jeffwidman
jeffwidman merged commit c89ba36 into main Aug 18, 2026
111 of 112 checks passed
@jeffwidman
jeffwidman deleted the restore-test-logger-state branch August 18, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants