-
Notifications
You must be signed in to change notification settings - Fork 143
[ISSUE #1360]🧪Add unit test for DeleteTopicRequestHeader #1361
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
Conversation
WalkthroughThe pull request introduces a new test module for the Changes
Assessment against linked issues
Possibly related 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
|
🔊@Fly-cmd-ops 🚀Thanks for your contribution 🎉. 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 #1361 +/- ##
==========================================
+ Coverage 20.92% 21.06% +0.13%
==========================================
Files 434 434
Lines 55062 55127 +65
==========================================
+ Hits 11524 11611 +87
+ Misses 43538 43516 -22 ☔ 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: 4
🧹 Outside diff range and nitpick comments (2)
rocketmq-remoting/src/protocol/header/delete_topic_request_header.rs (2)
74-89
: Add assertion to verify topic_request_header absence.While the test verifies the topic field conversion, it should also assert that no topic_request_header fields are present in the resulting map.
Add this assertion after line 88:
assert_eq!( map.get(&CheetahString::from_static_str(DeleteTopicRequestHeader::TOPIC)) .unwrap(), &CheetahString::from("test_topic") ); + // Verify no topic_request_header fields are present + assert_eq!(map.len(), 1);
67-150
: Consider adding tests for edge cases.While the current tests cover basic functionality, consider adding tests for:
- Empty string topics
- Very long topic names
- Special characters in topic names
- Invalid topic_request_header field values
This would improve the robustness of the test suite.
Would you like me to provide example implementations for these test cases?
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
rocketmq-remoting/src/protocol/header/delete_topic_request_header.rs
(1 hunks)
🔇 Additional comments (1)
rocketmq-remoting/src/protocol/header/delete_topic_request_header.rs (1)
67-73
: LGTM! Test module setup is correct.
The test module is properly configured with necessary imports and test attribute.
#[test] | ||
fn delete_topic_request_header_from_map_missing_topic() { | ||
let map = HashMap::new(); | ||
|
||
let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap(); | ||
assert_eq!(header.topic, CheetahString::default()); | ||
assert!(!header.topic_request_header.is_none()); | ||
} |
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.
Fix incorrect assertion for topic_request_header.
The test has the same logical error as the delete_topic_request_header_from_map test:
- Empty map shouldn't result in Some(topic_request_header)
- The double negative makes the code harder to read
Fix the assertion:
let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap();
assert_eq!(header.topic, CheetahString::default());
- assert!(!header.topic_request_header.is_none());
+ assert!(header.topic_request_header.is_none());
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
#[test] | |
fn delete_topic_request_header_from_map_missing_topic() { | |
let map = HashMap::new(); | |
let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap(); | |
assert_eq!(header.topic, CheetahString::default()); | |
assert!(!header.topic_request_header.is_none()); | |
} | |
#[test] | |
fn delete_topic_request_header_from_map_missing_topic() { | |
let map = HashMap::new(); | |
let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap(); | |
assert_eq!(header.topic, CheetahString::default()); | |
assert!(header.topic_request_header.is_none()); | |
} |
#[test] | ||
fn delete_topic_request_header_from_map() { | ||
let mut map = HashMap::new(); | ||
map.insert( | ||
CheetahString::from_static_str(DeleteTopicRequestHeader::TOPIC), | ||
CheetahString::from("test_topic"), | ||
); | ||
|
||
let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap(); | ||
assert_eq!(header.topic, CheetahString::from("test_topic")); | ||
assert!(!header.topic_request_header.is_none()); | ||
} | ||
|
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.
Fix incorrect assertion for topic_request_header.
There's a logical error in the test:
- The map doesn't contain any topic_request_header fields
- The assertion
!header.topic_request_header.is_none()
expects topic_request_header to be Some - The double negative makes the code harder to read
Fix the assertion:
let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap();
assert_eq!(header.topic, CheetahString::from("test_topic"));
- assert!(!header.topic_request_header.is_none());
+ assert!(header.topic_request_header.is_none());
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
#[test] | |
fn delete_topic_request_header_from_map() { | |
let mut map = HashMap::new(); | |
map.insert( | |
CheetahString::from_static_str(DeleteTopicRequestHeader::TOPIC), | |
CheetahString::from("test_topic"), | |
); | |
let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap(); | |
assert_eq!(header.topic, CheetahString::from("test_topic")); | |
assert!(!header.topic_request_header.is_none()); | |
} | |
#[test] | |
fn delete_topic_request_header_from_map() { | |
let mut map = HashMap::new(); | |
map.insert( | |
CheetahString::from_static_str(DeleteTopicRequestHeader::TOPIC), | |
CheetahString::from("test_topic"), | |
); | |
let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap(); | |
assert_eq!(header.topic, CheetahString::from("test_topic")); | |
assert!(header.topic_request_header.is_none()); | |
} |
#[test] | ||
fn delete_topic_request_header_to_map_with_topic_request_header() { | ||
let topic_request_header = TopicRequestHeader { | ||
// Initialize fields as needed | ||
rpc_request_header: None, | ||
lo: None, | ||
}; | ||
let header = DeleteTopicRequestHeader { | ||
topic: CheetahString::from("test_topic"), | ||
topic_request_header: Some(topic_request_header), | ||
}; | ||
|
||
let map = header.to_map().unwrap(); | ||
assert_eq!( | ||
map.get(&CheetahString::from_static_str( | ||
DeleteTopicRequestHeader::TOPIC | ||
)) | ||
.unwrap(), | ||
&CheetahString::from("test_topic") | ||
); | ||
// Add assertions for fields from topic_request_header | ||
} |
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.
Complete the test implementation for topic_request_header fields.
The test is incomplete:
- The comment "Initialize fields as needed" suggests missing implementation
- No assertions for topic_request_header fields in the resulting map
- The test doesn't verify the behavior of the flattened fields
Consider implementing the test like this:
let topic_request_header = TopicRequestHeader {
- // Initialize fields as needed
- rpc_request_header: None,
- lo: None,
+ rpc_request_header: Some(RpcRequestHeader {
+ // Initialize with meaningful test values
+ }),
+ lo: Some(42),
};
// ... existing code ...
assert_eq!(
map.get(&CheetahString::from_static_str(DeleteTopicRequestHeader::TOPIC))
.unwrap(),
&CheetahString::from("test_topic")
);
- // Add assertions for fields from topic_request_header
+ // Verify topic_request_header fields
+ assert_eq!(
+ map.get(&CheetahString::from_static_str("lo")).unwrap(),
+ &CheetahString::from("42")
+ );
+ // Add assertions for other topic_request_header fields
Committable suggestion skipped: line range outside the PR's diff.
#[test] | ||
fn delete_topic_request_header_from_map_with_topic_request_header() { | ||
let mut map = HashMap::new(); | ||
map.insert( | ||
CheetahString::from_static_str(DeleteTopicRequestHeader::TOPIC), | ||
CheetahString::from("test_topic"), | ||
); | ||
// Add entries for fields from topic_request_header | ||
|
||
let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap(); | ||
assert_eq!(header.topic, CheetahString::from("test_topic")); | ||
assert!(header.topic_request_header.is_some()); | ||
// Add assertions for fields from topic_request_header | ||
} |
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.
Complete the test implementation for topic_request_header fields.
The test is incomplete:
- The comment suggests missing topic_request_header field entries
- No actual verification of the topic_request_header field values
Complete the implementation:
let mut map = HashMap::new();
map.insert(
CheetahString::from_static_str(DeleteTopicRequestHeader::TOPIC),
CheetahString::from("test_topic"),
);
- // Add entries for fields from topic_request_header
+ // Add topic_request_header fields
+ map.insert(
+ CheetahString::from_static_str("lo"),
+ CheetahString::from("42")
+ );
+ // Add other topic_request_header fields as needed
let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap();
assert_eq!(header.topic, CheetahString::from("test_topic"));
assert!(header.topic_request_header.is_some());
- // Add assertions for fields from topic_request_header
+ if let Some(topic_request_header) = header.topic_request_header {
+ assert_eq!(topic_request_header.lo, Some(42));
+ // Add assertions for other fields
+ }
Committable suggestion skipped: line range outside the PR's diff.
Which Issue(s) This PR Fixes(Closes)
Fixes #1360
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
DeleteTopicRequestHeader
struct, enhancing test coverage for its conversion methods.