-
Notifications
You must be signed in to change notification settings - Fork 144
[ISSUE #1152] Add test case for MessageQueue #1153
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,3 +140,82 @@ impl Default for MessageQueue { | |
MessageQueue::new() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn new_message_queue_has_default_values() { | ||
let mq = MessageQueue::new(); | ||
assert_eq!(mq.get_topic(), ""); | ||
assert_eq!(mq.get_broker_name(), ""); | ||
assert_eq!(mq.get_queue_id(), 0); | ||
} | ||
|
||
#[test] | ||
fn from_other_creates_identical_copy() { | ||
let mq1 = MessageQueue::from_parts("topic1", "broker1", 1); | ||
let mq2 = MessageQueue::from_other(&mq1); | ||
assert_eq!(mq1, mq2); | ||
} | ||
|
||
#[test] | ||
fn from_parts_creates_message_queue_with_given_values() { | ||
let mq = MessageQueue::from_parts("topic1", "broker1", 1); | ||
assert_eq!(mq.get_topic(), "topic1"); | ||
assert_eq!(mq.get_broker_name(), "broker1"); | ||
assert_eq!(mq.get_queue_id(), 1); | ||
} | ||
|
||
#[test] | ||
fn set_topic_updates_topic() { | ||
let mut mq = MessageQueue::new(); | ||
mq.set_topic(CheetahString::from("new_topic")); | ||
assert_eq!(mq.get_topic(), "new_topic"); | ||
} | ||
|
||
#[test] | ||
fn set_broker_name_updates_broker_name() { | ||
let mut mq = MessageQueue::new(); | ||
mq.set_broker_name(CheetahString::from("new_broker")); | ||
assert_eq!(mq.get_broker_name(), "new_broker"); | ||
} | ||
|
||
#[test] | ||
fn set_queue_id_updates_queue_id() { | ||
let mut mq = MessageQueue::new(); | ||
mq.set_queue_id(10); | ||
assert_eq!(mq.get_queue_id(), 10); | ||
} | ||
|
||
#[test] | ||
fn message_queue_equality() { | ||
let mq1 = MessageQueue::from_parts("topic1", "broker1", 1); | ||
let mq2 = MessageQueue::from_parts("topic1", "broker1", 1); | ||
assert_eq!(mq1, mq2); | ||
} | ||
|
||
#[test] | ||
fn message_queue_inequality() { | ||
let mq1 = MessageQueue::from_parts("topic1", "broker1", 1); | ||
let mq2 = MessageQueue::from_parts("topic2", "broker2", 2); | ||
assert_ne!(mq1, mq2); | ||
} | ||
|
||
#[test] | ||
fn message_queue_ordering() { | ||
let mq1 = MessageQueue::from_parts("topic1", "broker1", 1); | ||
let mq2 = MessageQueue::from_parts("topic1", "broker1", 2); | ||
assert!(mq1 < mq2); | ||
} | ||
|
||
#[test] | ||
fn message_queue_display_format() { | ||
let mq = MessageQueue::from_parts("topic1", "broker1", 1); | ||
assert_eq!( | ||
format!("{}", mq), | ||
"MessageQueue [topic=topic1, broker_name=broker1, queue_id=1]" | ||
); | ||
} | ||
} | ||
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. 🛠️ Refactor suggestion Add tests for Hash and Default implementations. The MessageQueue struct implements both Hash and Default traits, but these aren't explicitly tested. Add these test cases: #[test]
fn test_hash_implementation() {
use std::collections::HashSet;
let mq1 = MessageQueue::from_parts("topic1", "broker1", 1);
let mq2 = MessageQueue::from_parts("topic1", "broker1", 1);
let mq3 = MessageQueue::from_parts("topic2", "broker1", 1);
let mut set = HashSet::new();
set.insert(mq1);
assert!(!set.insert(mq2)); // Should return false as equivalent item exists
assert!(set.insert(mq3)); // Should return true as this is a new item
}
#[test]
fn test_default_matches_new() {
let default_mq = MessageQueue::default();
let new_mq = MessageQueue::new();
assert_eq!(default_mq, new_mq);
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion
Enhance ordering test coverage.
The current test only verifies ordering based on queue_id. Consider adding tests for:
Here's a suggested implementation:
📝 Committable suggestion