-
Notifications
You must be signed in to change notification settings - Fork 233
[ISSUE #6210][Test🧪] Add unit tests for OffsetMovedEvent #6319
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
8b7dc9d
2ebc08a
2b7edff
ede959f
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 |
|---|---|---|
|
|
@@ -67,3 +67,91 @@ impl std::fmt::Display for OffsetMovedEvent { | |
| ) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn offset_moved_event_field_initialization() { | ||
| let body: OffsetMovedEvent = OffsetMovedEvent { | ||
| consumer_group: "test_group".to_string(), | ||
| message_queue: MessageQueue::new(), | ||
| offset_request: 100, | ||
| offset_new: 200, | ||
| }; | ||
| assert_eq!(body.get_consumer_group(), "test_group"); | ||
| assert_eq!(body.get_offset_request(), 100); | ||
| assert_eq!(body.get_offset_new(), 200); | ||
| assert_eq!(body.get_message_queue(), &MessageQueue::new()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn offset_moved_event_setters() { | ||
| let mut body = OffsetMovedEvent { | ||
| consumer_group: "test_group".to_string(), | ||
| message_queue: MessageQueue::new(), | ||
| offset_request: 100, | ||
| offset_new: 200, | ||
| }; | ||
| body.set_consumer_group("new_group".to_string()); | ||
| body.set_message_queue(MessageQueue::new()); | ||
| body.set_offset_request(150); | ||
| body.set_offset_new(250); | ||
| assert_eq!(body.get_consumer_group(), "new_group"); | ||
| assert_eq!(body.get_message_queue(), &MessageQueue::new()); | ||
| assert_eq!(body.get_offset_request(), 150); | ||
| assert_eq!(body.get_offset_new(), 250); | ||
| } | ||
|
|
||
| #[test] | ||
| fn offset_moved_event_getters() { | ||
| let body = OffsetMovedEvent { | ||
| consumer_group: "another_group".to_string(), | ||
| message_queue: MessageQueue::new(), | ||
| offset_request: 300, | ||
| offset_new: 400, | ||
| }; | ||
| assert_eq!(body.get_consumer_group(), "another_group"); | ||
| assert_eq!(body.get_offset_request(), 300); | ||
| assert_eq!(body.get_offset_new(), 400); | ||
| } | ||
|
|
||
| #[test] | ||
| fn offset_moved_event_display() { | ||
| let body = OffsetMovedEvent { | ||
| consumer_group: "test_group".to_string(), | ||
| message_queue: MessageQueue::new(), | ||
| offset_request: 100, | ||
| offset_new: 200, | ||
| }; | ||
| let display = format!("{}", body); | ||
| assert!(display.contains("OffsetMovedEvent")); | ||
| assert!(display.contains("consumer_group=test_group")); | ||
| assert!(display.contains("offset_request=100")); | ||
| assert!(display.contains("offset_new=200")); | ||
| } | ||
| #[test] | ||
| fn offset_moved_event_serialization() { | ||
| let body = OffsetMovedEvent { | ||
| consumer_group: "test_group".to_string(), | ||
| message_queue: MessageQueue::new(), | ||
| offset_request: 100, | ||
| offset_new: 200, | ||
| }; | ||
| let json = serde_json::to_string(&body).unwrap(); | ||
| assert!(json.contains("\"consumer_group\":\"test_group\"")); | ||
| assert!(json.contains("\"offset_request\":100")); | ||
| assert!(json.contains("\"offset_new\":200")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn offset_moved_event_deserialization() { | ||
| let json = r#"{"consumer_group":"test_group","message_queue":{"topic":"","brokerName":"","queueId":0},"offset_request":100,"offset_new":200}"#; | ||
| let body: OffsetMovedEvent = serde_json::from_str(json).unwrap(); | ||
| assert_eq!(body.get_consumer_group(), "test_group"); | ||
| assert_eq!(body.get_offset_request(), 100); | ||
| assert_eq!(body.get_offset_new(), 200); | ||
| assert_eq!(body.get_message_queue(), &MessageQueue::new()); | ||
| } | ||
| } | ||
|
Comment on lines
71
to
157
|
||
Uh oh!
There was an error while loading. Please reload this page.