Skip to main content

rocketmq_protocol/protocol/body/
subscription_group_list.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 serde::Deserialize;
16use serde::Serialize;
17
18use crate::protocol::subscription::subscription_group_config::SubscriptionGroupConfig;
19
20#[derive(Debug, Clone, Serialize, Deserialize, Default)]
21#[serde(rename_all = "camelCase")]
22pub struct SubscriptionGroupList {
23    pub group_config_list: Vec<SubscriptionGroupConfig>,
24}
25
26#[cfg(test)]
27mod tests {
28    use cheetah_string::CheetahString;
29
30    use super::*;
31
32    #[test]
33    fn subscription_group_list_round_trips() {
34        let body = SubscriptionGroupList {
35            group_config_list: vec![SubscriptionGroupConfig::new(CheetahString::from_static_str("group-a"))],
36        };
37
38        let json = serde_json::to_string(&body).expect("serialize subscription group list");
39        assert!(json.contains("\"groupConfigList\""));
40        assert!(json.contains("\"groupName\":\"group-a\""));
41
42        let decoded: SubscriptionGroupList = serde_json::from_str(&json).expect("deserialize subscription group list");
43        assert_eq!(decoded.group_config_list.len(), 1);
44        assert_eq!(decoded.group_config_list[0].group_name(), "group-a");
45    }
46}