rocketmq_remoting/protocol/header/
get_lite_topic_info_request_header.rs1use cheetah_string::CheetahString;
16use rocketmq_macros::RequestHeaderCodecV2;
17use serde::Deserialize;
18use serde::Serialize;
19
20#[derive(Clone, Debug, Serialize, Deserialize, RequestHeaderCodecV2)]
21#[serde(rename_all = "camelCase")]
22pub struct GetLiteTopicInfoRequestHeader {
23 #[required]
24 pub parent_topic: CheetahString,
25
26 #[required]
27 pub lite_topic: CheetahString,
28}
29
30#[cfg(test)]
31mod tests {
32 use std::collections::HashMap;
33
34 use super::*;
35 use crate::protocol::command_custom_header::CommandCustomHeader;
36 use crate::protocol::command_custom_header::FromMap;
37
38 #[test]
39 fn get_lite_topic_info_request_header_creation() {
40 let header = GetLiteTopicInfoRequestHeader {
41 parent_topic: CheetahString::from("parent_topic"),
42 lite_topic: CheetahString::from("lite_topic"),
43 };
44
45 assert_eq!(header.parent_topic, CheetahString::from("parent_topic"));
46 assert_eq!(header.lite_topic, CheetahString::from("lite_topic"));
47 }
48
49 #[test]
50 fn get_lite_topic_info_request_header_serializes_to_map() {
51 let header = GetLiteTopicInfoRequestHeader {
52 parent_topic: CheetahString::from("test_parent"),
53 lite_topic: CheetahString::from("test_lite"),
54 };
55
56 let map = header.to_map().unwrap();
57 assert_eq!(
58 map.get(&CheetahString::from_static_str("parentTopic")).unwrap(),
59 "test_parent"
60 );
61 assert_eq!(
62 map.get(&CheetahString::from_static_str("liteTopic")).unwrap(),
63 "test_lite"
64 );
65 }
66
67 #[test]
68 fn get_lite_topic_info_request_header_deserializes_from_map() {
69 let mut map = HashMap::new();
70 map.insert(
71 CheetahString::from_static_str("parentTopic"),
72 CheetahString::from("deserialized_parent"),
73 );
74 map.insert(
75 CheetahString::from_static_str("liteTopic"),
76 CheetahString::from("deserialized_lite"),
77 );
78
79 let header = <GetLiteTopicInfoRequestHeader as FromMap>::from(&map).unwrap();
80 assert_eq!(header.parent_topic, CheetahString::from("deserialized_parent"));
81 assert_eq!(header.lite_topic, CheetahString::from("deserialized_lite"));
82 }
83
84 #[test]
85 fn get_lite_topic_info_request_header_clone() {
86 let header = GetLiteTopicInfoRequestHeader {
87 parent_topic: CheetahString::from("parent"),
88 lite_topic: CheetahString::from("lite"),
89 };
90
91 let cloned = header.clone();
92 assert_eq!(header.parent_topic, cloned.parent_topic);
93 assert_eq!(header.lite_topic, cloned.lite_topic);
94 }
95
96 #[test]
97 fn get_lite_topic_info_request_header_debug() {
98 let header = GetLiteTopicInfoRequestHeader {
99 parent_topic: CheetahString::from("parent"),
100 lite_topic: CheetahString::from("lite"),
101 };
102
103 let debug_str = format!("{:?}", header);
104 assert!(debug_str.contains("parent"));
105 assert!(debug_str.contains("lite"));
106 }
107}