[test] Add tests for logger.ServerFileLogger.Close#3159
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test] Add tests for logger.ServerFileLogger.Close#3159github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Increase test coverage for the ServerFileLogger.Close method from 58.8% to 94.1%, while also bringing Log(), getOrCreateLogger(), and all public server-log helpers to 100% coverage. Tests added: - TestServerFileLoggerClose_NilReceiver: nil-receiver safety check - TestServerFileLoggerClose_EmptyFiles: no-op close with empty maps - TestServerFileLoggerClose_SyncError: Sync() failure propagation and firstErr tracking via a pre-closed file descriptor - TestServerFileLoggerClose_FirstErrorTracking: first-error-wins behaviour across multiple failing files - TestServerFileLoggerClose_ValidFiles: happy path (all files close OK) - TestServerFileLoggerClose_CloseTwice: idempotent close safety - TestServerFileLoggerLog_NilReceiver: nil-receiver safety for Log() - TestServerFileLoggerLog_SyncError: Sync() failure inside Log() - TestServerFileLoggerGetOrCreate_FileCreationError: os.OpenFile failure in getOrCreateLogger fallback path Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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:
ServerFileLogger.CloseFunction Analyzed
internal/loggerServerFileLogger.Closeinternal/logger/server_file_logger.go:108Why This Function?
ServerFileLogger.Closehad the lowest real test coverage (58.8%) among non-env-gated functions in the testable subset of the codebase. Its complexity comes from:nil *ServerFileLogger)firstErrcaptures the first Sync or Close failure without being overwritten by later errorsAll of these paths except the "Sync succeeds but Close fails" branch (which requires NFS-level failure to trigger) are now exercised.
Tests Added
TestServerFileLoggerClose_NilReceiverClose()TestServerFileLoggerClose_EmptyFilesTestServerFileLoggerClose_SyncErrorfile.Sync()error →firstErrsetTestServerFileLoggerClose_FirstErrorTrackingTestServerFileLoggerClose_ValidFilesTestServerFileLoggerClose_CloseTwiceTestServerFileLoggerLog_NilReceiverLog()TestServerFileLoggerLog_SyncErrorfile.Sync()error insideLog()does not panicTestServerFileLoggerGetOrCreate_FileCreationErroros.OpenFilefailure ingetOrCreateLogger()gracefully falls back toLogDebugCoverage Report
All existing tests continue to pass.
Generated by Test Coverage Improver
Next run should target
writeToFile(63.6%) orlogEntry(66.7%)