-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add Abort method #796
Conversation
WalkthroughThe changes introduce a new Changes
Possibly related PRs
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
contracts/http/request.go
(1 hunks)mocks/http/ContextRequest.go
(1 hunks)
🔇 Additional comments (5)
contracts/http/request.go (2)
75-76
: Well-structured method for a more flexible abort flow.
The new Abort(code ...int)
method allows optional status codes and eases migration from multiple specialized methods. Good job on adopting a variadic approach!
82-82
: Deprecated JSON-based abort.
Marking AbortWithStatusJson
as deprecated signals a transition toward more composable methods. Ensure existing code that relies on this method is prepared to switch to the recommended approach.
mocks/http/ContextRequest.go (3)
31-40
: Accurate variadic implementation in the mock.
The approach of capturing variadic integer arguments and passing them to the mock.Called
function is consistent and correctly matches the interface method’s signature.
42-52
: Helper method aligns with standard mock expectations.
The ContextRequest_Abort_Call
struct and its constructor method enhance the usability of chained mock expectations. This is an effective testing pattern.
54-75
: Robust testing hooks for custom logic.
By providing Run
, Return
, and RunAndReturn
, this mock supports flexible testing scenarios. Good job covering a wide range of use cases to handle different code paths.
// AbortWithStatus aborts the request with the specified HTTP status code. | ||
// DEPRECATED: Use Abort instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Update required: Replace AbortWithStatus
with Abort
across the codebase
The verification confirms that both the old AbortWithStatus
and the new Abort
methods exist in the codebase. The following changes are needed:
- Replace
ctx.Request().AbortWithStatus(httpcontract.StatusTooManyRequests)
withctx.Request().Abort(httpcontract.StatusTooManyRequests)
in:http/middleware/throttle.go
http/limit/limit.go
- Update test mocks and implementations in:
session/middleware/start_session_test.go
http/middleware/throttle_test.go
log/logrus_writer_test.go
mocks/http/ContextRequest.go
🔗 Analysis chain
Note on deprecation strategy.
Deprecating AbortWithStatus(code int)
in favor of Abort(code ...int)
is a good move. Consider updating any references to the older method across the codebase to avoid confusion.
Generate a script to locate calls to AbortWithStatus
:
Update test mocks and actual implementations to use Abort
Based on the search results, AbortWithStatus
is still actively used in several places:
- Production code:
http/middleware/throttle.go
http/limit/limit.go
- Test files and mocks:
session/middleware/start_session_test.go
http/middleware/throttle_test.go
log/logrus_writer_test.go
mocks/http/ContextRequest.go
Let's verify if the new Abort
method is already defined:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
rg "AbortWithStatus"
Length of output: 3584
Script:
#!/bin/bash
rg "func.*Abort\(" -g '!vendor/**'
Length of output: 419
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #796 +/- ##
=======================================
Coverage 69.81% 69.81%
=======================================
Files 217 217
Lines 18825 18825
=======================================
Hits 13142 13142
Misses 4969 4969
Partials 714 714 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
session/middleware/start_session_test.go (1)
291-293
: Implement or Document the New Abort Method in Test Code.These lines introduce a new method signature
Abort(code ...int)
without an implementation or explanatory comment. Consider providing at least a no-op comment, or implement minimal logic to clarify intent for future maintainers.func (r *TestRequest) Abort(code ...int) { + // Intentionally left blank for testing purposes }
http/middleware/throttle_test.go (1)
565-567
: Finalize or Document the New Abort Method in Tests.Similar to the other test file, the newly added
Abort(code ...int)
is empty and may benefit from a brief comment explaining its purpose as a stub for testing.func (r *TestRequest) Abort(code ...int) { + // No action needed. Stub for testing scenario where request aborts. }
log/logrus_writer_test.go (2)
753-754
: Consider adding a minimal implementation or a comment on the purpose ofAbort
.
Currently, theAbort
method is empty, which might be fine if it's only used in tests. However, adding a simple comment or minimal logic helps future contributors understand why no action is needed or if there are future plans.
756-758
: MarkAbortWithStatus
as deprecated or remove if unneeded.
SinceAbortWithStatus
is replaced byAbort
, and here it’s merely apanic
, consider marking it as deprecated or removing it entirely if it’s no longer used.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
http/limit/limit.go
(1 hunks)http/middleware/throttle.go
(1 hunks)http/middleware/throttle_test.go
(1 hunks)log/logrus_writer_test.go
(1 hunks)session/middleware/start_session_test.go
(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
http/middleware/throttle.go
[warning] 68-68: http/middleware/throttle.go#L68
Added line #L68 was not covered by tests
http/limit/limit.go
[warning] 52-52: http/limit/limit.go#L52
Added line #L52 was not covered by tests
🔇 Additional comments (4)
http/limit/limit.go (1)
52-52
: Consider Increasing Test Coverage for the New Abort Call.
The newly introduced Abort call at line 52 may not be covered by tests, according to static analysis. If feasible, adding a simple test case that triggers this rate-limiting scenario would help ensure overall coverage and verify correctness.
Do you want me to propose a test snippet to exercise this code path?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 52-52: http/limit/limit.go#L52
Added line #L52 was not covered by tests
http/middleware/throttle.go (1)
68-68
: Increase Test Coverage for the Updated Abort Logic.
The request abort logic at line 68 was updated to use Abort
, but it may not be covered by tests. Please consider adding or updating test scenarios to confirm that any requests exceeding the limit trigger the correct response status code.
I'd be glad to help generate a suitable test case or script to confirm coverage if you like.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 68-68: http/middleware/throttle.go#L68
Added line #L68 was not covered by tests
session/middleware/start_session_test.go (1)
294-296
: Panic in AbortWithStatus
– Confirm It's Needed.
AbortWithStatus
now panics. While this might be intended for test stubbing, ensure no legitimate test paths require AbortWithStatus
. If it’s unneeded, consider removing or adding a clarifying comment.
http/middleware/throttle_test.go (1)
568-570
: Confirm No Remaining Dependencies on AbortWithStatus
.
Since this method immediately panics, verify that no tests rely on AbortWithStatus
being functional. If not used, the panic is acceptable; otherwise, consider meeting any usage requirements or removing the method if it’s obsolete.
📑 Description
Summary by CodeRabbit
New Features
Abort
method to request handling, providing more flexible request termination options.Deprecation
AbortWithStatus
andAbortWithStatusJson
methods in favor of the newAbort
method.Bug Fixes