-
Notifications
You must be signed in to change notification settings - Fork 144
[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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -64,3 +64,87 @@ impl FromMap for DeleteTopicRequestHeader { | |||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
#[cfg(test)] | ||||||||||||||||||||||||||||||||||||||||||||||||||
mod tests { | ||||||||||||||||||||||||||||||||||||||||||||||||||
use std::collections::HashMap; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
use super::*; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
#[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||
fn delete_topic_request_header_to_map() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
let header = DeleteTopicRequestHeader { | ||||||||||||||||||||||||||||||||||||||||||||||||||
topic: CheetahString::from("test_topic"), | ||||||||||||||||||||||||||||||||||||||||||||||||||
topic_request_header: None, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
let map = header.to_map().unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
assert_eq!( | ||||||||||||||||||||||||||||||||||||||||||||||||||
map.get(&CheetahString::from_static_str( | ||||||||||||||||||||||||||||||||||||||||||||||||||
DeleteTopicRequestHeader::TOPIC | ||||||||||||||||||||||||||||||||||||||||||||||||||
)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
.unwrap(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
&CheetahString::from("test_topic") | ||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
#[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 | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
#[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()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+114
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
#[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 | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+127
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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
+ }
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
#[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()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+142
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
} |
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:
Consider implementing the test like this: