[ISSUE #1190]🧪Add unit test for CMResult#1191
Conversation
WalkthroughThe changes introduce a new test module for the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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
Documentation and Community
|
|
🚀Thanks for your contribution🎉 @${prCreator}. CodeRabbit(AI) will review your code first🔥 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1191 +/- ##
==========================================
+ Coverage 16.68% 16.81% +0.13%
==========================================
Files 427 427
Lines 52836 52860 +24
==========================================
+ Hits 8815 8888 +73
+ Misses 44021 43972 -49 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
rocketmq-remoting/src/protocol/body/cm_result.rs (1)
173-177: Enhance error case validation in deserialize_unknown_variant testThe test verifies that an error occurs but doesn't validate the specific error type or message. Consider enhancing it to ensure the correct error variant is returned.
#[test] fn deserialize_unknown_variant() { - let result: Result<CMResult, _> = serde_json::from_str("\"UNKNOWN\""); - assert!(result.is_err()); + let result = serde_json::from_str::<CMResult>("\"UNKNOWN\""); + match result { + Err(err) => { + assert!(err.is_data()); + assert!(err.to_string().contains("unknown variant")); + } + Ok(_) => panic!("Expected error for unknown variant"), + } }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
rocketmq-remoting/src/protocol/body/cm_result.rs(1 hunks)
🔇 Additional comments (1)
rocketmq-remoting/src/protocol/body/cm_result.rs (1)
137-142: Test module structure follows Rust best practices
The test module is well-organized with:
- Proper isolation using
#[cfg(test)] - Clear imports and module organization
- Good use of
super::*for accessing the tested items
| #[test] | ||
| fn serialize_cr_success() { | ||
| let result = serde_json::to_string(&CMResult::CRSuccess).unwrap(); | ||
| assert_eq!(result, "\"CR_SUCCESS\""); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_cr_success() { | ||
| let result: CMResult = serde_json::from_str("\"CR_SUCCESS\"").unwrap(); | ||
| assert_eq!(result, CMResult::CRSuccess); | ||
| } | ||
|
|
||
| #[test] | ||
| fn from_i32_to_cmresult() { | ||
| let result = CMResult::from(0); | ||
| assert_eq!(result, CMResult::CRSuccess); | ||
| } | ||
|
|
||
| #[test] | ||
| fn from_cmresult_to_i32() { | ||
| let result: i32 = CMResult::CRSuccess.into(); | ||
| assert_eq!(result, 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn display_cr_success() { | ||
| let result = format!("{}", CMResult::CRSuccess); | ||
| assert_eq!(result, "CR_SUCCESS"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_unknown_variant() { | ||
| let result: Result<CMResult, _> = serde_json::from_str("\"UNKNOWN\""); | ||
| assert!(result.is_err()); | ||
| } | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Enhance test coverage for all CMResult variants
While the current tests are well-structured, they only cover the CRSuccess variant. Consider adding tests for:
- All other variants (CRLater, CRRollback, CRCommit, CRThrowException, CRReturnNull)
- Edge cases in From conversion (e.g., negative numbers, values > 5)
- Serialization/deserialization of all variants
Would you like me to provide additional test cases to cover these scenarios?
Which Issue(s) This PR Fixes(Closes)
Fixes #1190
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
CMResultenum.