Skip to content

Add tests for logger to increase coverage#648

Open
Hmnt39 wants to merge 5 commits intomasterfrom
hemant/logger_coverage
Open

Add tests for logger to increase coverage#648
Hmnt39 wants to merge 5 commits intomasterfrom
hemant/logger_coverage

Conversation

@Hmnt39
Copy link
Copy Markdown

@Hmnt39 Hmnt39 commented Mar 26, 2026

This PR improves test coverage for the logging and callback utilities by adding unit tests.

@Hmnt39 Hmnt39 force-pushed the hemant/logger_coverage branch from 7fab6d6 to f3875c1 Compare March 26, 2026 09:39
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.92%. Comparing base (f156431) to head (4cefaea).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #648      +/-   ##
==========================================
+ Coverage   77.71%   77.92%   +0.21%     
==========================================
  Files         136      136              
  Lines       13226    13226              
  Branches     1991     1991              
==========================================
+ Hits        10278    10306      +28     
+ Misses       2112     2082      -30     
- Partials      836      838       +2     

see 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Hmnt39 Hmnt39 marked this pull request as ready for review March 26, 2026 10:43
@Hmnt39 Hmnt39 requested a review from a team as a code owner March 26, 2026 10:43
@Hmnt39
Copy link
Copy Markdown
Author

Hmnt39 commented Apr 1, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces new unit tests for CallbackUtil and expands the LoggingTest suite to verify different logger configurations and levels. Feedback was provided regarding a potential IOException on Windows in the new logging tests, where the test.log file is deleted before the ServiceProvider is disposed, which may cause file lock conflicts.

@Hmnt39 Hmnt39 requested a review from devendra-lohar April 1, 2026 06:47
devendra-lohar
devendra-lohar previously approved these changes Apr 1, 2026
Copy link
Copy Markdown

@devendra-lohar devendra-lohar left a comment

Choose a reason for hiding this comment

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

LGTM

@Hmnt39 Hmnt39 added the waiting-for-risk-review Waiting for a member of the risk review team to take an action label Apr 1, 2026
} // provider is disposed here

// Cleanup test.log file if created
if (File.Exists("test.log"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If logType = "file", you should Assert that the file exists, and then delete it if FileLogger creates a file on initialization. If it does not, then we don't need this block.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added the cleanup when config type is file

Comment on lines +140 to +161
switch (logType)
{
case "console":
services.AddSingleton(new LoggerConfig
{
Console = new ConsoleConfig { Level = "information" }
});
break;
case "file":
services.AddSingleton(new LoggerConfig
{
File = new FileConfig { Level = "warning", Path = "test.log" }
});
break;
case "trace-listener":
services.AddSingleton(new LoggerConfig
{
TraceListener = new TraceListenerConfig { Level = "error" }
});
break;
}
services.AddLogger();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This whole block is mostly duplicated with the test below, really should be a common method imo.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

add a common method for duplicated code

Comment on lines +218 to +227
Assert.NotNull(retrievedConfig.Console);
Assert.Equal(level, retrievedConfig.Console.Level);
break;
case "file":
Assert.NotNull(retrievedConfig.File);
Assert.Equal(level, retrievedConfig.File.Level);
break;
case "trace-listener":
Assert.NotNull(retrievedConfig.TraceListener);
Assert.Equal(level, retrievedConfig.TraceListener.Level);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is only asserting the level of the logger configuration file, not the logger itself.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added assertion for logger and log level too.

@Hmnt39 Hmnt39 removed the waiting-for-risk-review Waiting for a member of the risk review team to take an action label Apr 1, 2026
@Hmnt39 Hmnt39 added the waiting-for-risk-review Waiting for a member of the risk review team to take an action label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-risk-review Waiting for a member of the risk review team to take an action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants