fix: export missing module functions and add tests#7
Conversation
Summary by CodeRabbit
WalkthroughThe PR adds public visibility metadata to the TSLog provider registration and introduces a test that validates logger inheritance across module hierarchy. ForRoot now sets ChangesLogger Public Visibility and Inheritance
🎯 2 (Simple) | ⏱️ ~8 minutes
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tslog_test.go (1)
58-74: ⚡ Quick winConsider extracting the duplicated controller logic.
The controller function here is nearly identical to the one in
createApp()(lines 16-31). Consider extracting the shared logic into a helper function to follow DRY principles and improve maintainability.♻️ Proposed refactor to extract shared controller
+func testController(module core.Module) core.Controller { + ctrl := module.NewController("test") + logger := tslog.Inject(module) + + ctrl.Get("", func(ctx core.Ctx) error { + logger.Info("Request processed", + "http", slog.Group("request", + "method", "GET", + "path", "/api/users", + "status", 200, + ), + "duration_ms", 150, + ) + return ctx.JSON(true) + }) + return ctrl +} + func createApp() *core.App { - ctrlFnc := func(module core.Module) core.Controller { - ctrl := module.NewController("test") - logger := tslog.Inject(module) - - ctrl.Get("", func(ctx core.Ctx) error { - logger.Info("Request processed", - "http", slog.Group("request", - "method", "GET", - "path", "/api/users", - "status", 200, - ), - "duration_ms", 150, - ) - return ctx.JSON(true) - }) - return ctrl - } - moduleFnc := func() core.Module { return core.NewModule(core.NewModuleOptions{ Imports: []core.Modules{tslog.ForRoot(slog.NewJSONHandler(os.Stdout, nil))}, - Controllers: []core.Controllers{ctrlFnc}, + Controllers: []core.Controllers{testController}, }) } return core.CreateFactory(moduleFnc) } func TestInherit(t *testing.T) { - ctrlFnc := func(module core.Module) core.Controller { - ctrl := module.NewController("test") - logger := tslog.Inject(module) - - ctrl.Get("", func(ctx core.Ctx) error { - logger.Info("Request processed", - "http", slog.Group("request", - "method", "GET", - "path", "/api/users", - "status", 200, - ), - "duration_ms", 150, - ) - return ctx.JSON(true) - }) - return ctrl - } - parentMod := func(module core.Module) core.Module { return module.New(core.NewModuleOptions{ Imports: []core.Modules{tslog.ForRoot(slog.NewJSONHandler(os.Stdout, nil))}, }) } childMod := func() core.Module { return core.NewModule(core.NewModuleOptions{ Imports: []core.Modules{parentMod}, - Controllers: []core.Controllers{ctrlFnc}, + Controllers: []core.Controllers{testController}, }) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tslog_test.go` around lines 58 - 74, The controller creation in ctrlFnc duplicates logic from createApp(): extract the shared handler into a single helper (e.g., makeTestController or registerLoggingRoute) that accepts a core.Module (or core.Controller) and returns/configures a controller; move the tslog.Inject(module) and the ctrl.Get(...) handler (the logger.Info call with slog.Group and ctx.JSON response) into that helper and then call it from both ctrlFnc and createApp() to remove duplication while keeping module.NewController, tslog.Inject, and ctrl.Get usage intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tslog_test.go`:
- Around line 58-74: The controller creation in ctrlFnc duplicates logic from
createApp(): extract the shared handler into a single helper (e.g.,
makeTestController or registerLoggingRoute) that accepts a core.Module (or
core.Controller) and returns/configures a controller; move the
tslog.Inject(module) and the ctrl.Get(...) handler (the logger.Info call with
slog.Group and ctx.JSON response) into that helper and then call it from both
ctrlFnc and createApp() to remove duplication while keeping
module.NewController, tslog.Inject, and ctrl.Get usage intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 40d1eb3f-f954-4279-9d53-92b96ec00475
📒 Files selected for processing (2)
tslog.gotslog_test.go
No description provided.