Skip to content

Commit

Permalink
[ISSUE #1330]🧪Add unit test for MessageModel
Browse files Browse the repository at this point in the history
  • Loading branch information
rust-learn-now committed Nov 26, 2024
1 parent ba543ed commit 45b6df4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions rocketmq-remoting/src/protocol/heartbeat/message_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,57 @@ impl Display for MessageModel {
write!(f, "{}", self.get_mode_cn())
}
}

#[cfg(test)]
mod tests {
use serde_json;

use super::*;

#[test]
fn serialize_message_model_broadcasting() {
let model = MessageModel::Broadcasting;
let serialized = serde_json::to_string(&model).unwrap();
assert_eq!(serialized, "\"BROADCASTING\"");
}

#[test]
fn serialize_message_model_clustering() {
let model = MessageModel::Clustering;
let serialized = serde_json::to_string(&model).unwrap();
assert_eq!(serialized, "\"CLUSTERING\"");
}

#[test]
fn deserialize_message_model_broadcasting() {
let json = "\"BROADCASTING\"";
let deserialized: MessageModel = serde_json::from_str(json).unwrap();
assert_eq!(deserialized, MessageModel::Broadcasting);
}

#[test]
fn deserialize_message_model_clustering() {
let json = "\"CLUSTERING\"";
let deserialized: MessageModel = serde_json::from_str(json).unwrap();
assert_eq!(deserialized, MessageModel::Clustering);
}

#[test]
fn deserialize_message_model_invalid() {
let json = "\"INVALID\"";
let deserialized: Result<MessageModel, _> = serde_json::from_str(json);
assert!(deserialized.is_err());
}

#[test]
fn display_message_model_broadcasting() {
let model = MessageModel::Broadcasting;
assert_eq!(model.to_string(), "BROADCASTING");
}

#[test]
fn display_message_model_clustering() {
let model = MessageModel::Clustering;
assert_eq!(model.to_string(), "CLUSTERING");
}
}

0 comments on commit 45b6df4

Please sign in to comment.