Skip to main content

rocketmq_remoting/protocol/header/
delete_topic_request_header.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use cheetah_string::CheetahString;
16use rocketmq_macros::RequestHeaderCodecV2;
17use serde::Deserialize;
18use serde::Serialize;
19
20use crate::rpc::topic_request_header::TopicRequestHeader;
21
22#[derive(Serialize, Deserialize, Debug, RequestHeaderCodecV2)]
23pub struct DeleteTopicRequestHeader {
24    #[required]
25    #[serde(rename = "topic")]
26    pub topic: CheetahString,
27
28    #[serde(flatten)]
29    pub topic_request_header: Option<TopicRequestHeader>,
30}
31
32#[cfg(test)]
33mod tests {
34    use std::collections::HashMap;
35
36    use super::*;
37    use crate::protocol::command_custom_header::CommandCustomHeader;
38    use crate::protocol::command_custom_header::FromMap;
39
40    #[test]
41    fn delete_topic_request_header_to_map() {
42        let header = DeleteTopicRequestHeader {
43            topic: CheetahString::from("test_topic"),
44            topic_request_header: None,
45        };
46
47        let map = header.to_map().unwrap();
48        assert_eq!(
49            map.get(&CheetahString::from_static_str(DeleteTopicRequestHeader::TOPIC))
50                .unwrap(),
51            &CheetahString::from("test_topic")
52        );
53    }
54
55    #[test]
56    fn delete_topic_request_header_to_map_with_topic_request_header() {
57        let topic_request_header = TopicRequestHeader {
58            // Initialize fields as needed
59            rpc_request_header: None,
60            lo: None,
61        };
62        let header = DeleteTopicRequestHeader {
63            topic: CheetahString::from("test_topic"),
64            topic_request_header: Some(topic_request_header),
65        };
66
67        let map = header.to_map().unwrap();
68        assert_eq!(
69            map.get(&CheetahString::from_static_str(DeleteTopicRequestHeader::TOPIC))
70                .unwrap(),
71            &CheetahString::from("test_topic")
72        );
73        // Add assertions for fields from topic_request_header
74    }
75
76    #[test]
77    fn delete_topic_request_header_from_map() {
78        let mut map = HashMap::new();
79        map.insert(
80            CheetahString::from_static_str(DeleteTopicRequestHeader::TOPIC),
81            CheetahString::from("test_topic"),
82        );
83
84        let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap();
85        assert_eq!(header.topic, CheetahString::from("test_topic"));
86        assert!(header.topic_request_header.is_some());
87    }
88
89    #[test]
90    fn delete_topic_request_header_from_map_with_topic_request_header() {
91        let mut map = HashMap::new();
92        map.insert(
93            CheetahString::from_static_str(DeleteTopicRequestHeader::TOPIC),
94            CheetahString::from("test_topic"),
95        );
96        // Add entries for fields from topic_request_header
97
98        let header = <DeleteTopicRequestHeader as FromMap>::from(&map).unwrap();
99        assert_eq!(header.topic, CheetahString::from("test_topic"));
100        assert!(header.topic_request_header.is_some());
101        // Add assertions for fields from topic_request_header
102    }
103}