rocketmq_remoting/protocol/header/
delete_subscription_group_request_header.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17use cheetah_string::CheetahString;
18use rocketmq_macros::RequestHeaderCodecV2;
19use serde::Deserialize;
20use serde::Serialize;
21
22use crate::rpc::rpc_request_header::RpcRequestHeader;
23
24#[derive(Clone, Debug, Serialize, Deserialize, Default, RequestHeaderCodecV2)]
25#[serde(rename_all = "camelCase")]
26pub struct DeleteSubscriptionGroupRequestHeader {
27    #[required]
28    pub group_name: CheetahString,
29
30    pub clean_offset: bool,
31
32    #[serde(flatten)]
33    pub rpc_request_header: Option<RpcRequestHeader>,
34}
35
36#[cfg(test)]
37mod tests {
38    use cheetah_string::CheetahString;
39
40    use super::*;
41
42    #[test]
43    fn delete_subscription_group_request_header_serializes_correctly() {
44        let header = DeleteSubscriptionGroupRequestHeader {
45            group_name: CheetahString::from_static_str("test_group"),
46            clean_offset: true,
47            rpc_request_header: None,
48        };
49        let serialized = serde_json::to_string(&header).unwrap();
50        let expected = r#"{"groupName":"test_group","cleanOffset":true}"#;
51        assert_eq!(serialized, expected);
52    }
53
54    #[test]
55    fn delete_subscription_group_request_header_deserializes_correctly() {
56        let data = r#"{"groupName":"test_group","cleanOffset":true}"#;
57        let header: DeleteSubscriptionGroupRequestHeader = serde_json::from_str(data).unwrap();
58        assert_eq!(
59            header.group_name,
60            CheetahString::from_static_str("test_group")
61        );
62        assert!(header.clean_offset);
63        assert!(header.rpc_request_header.is_some());
64    }
65
66    #[test]
67    fn delete_subscription_group_request_header_handles_missing_optional_fields() {
68        let data = r#"{"groupName":"test_group","cleanOffset":false}"#;
69        let header: DeleteSubscriptionGroupRequestHeader = serde_json::from_str(data).unwrap();
70        assert_eq!(
71            header.group_name,
72            CheetahString::from_static_str("test_group")
73        );
74        assert!(!header.clean_offset);
75        assert!(header.rpc_request_header.is_some());
76    }
77
78    #[test]
79    fn delete_subscription_group_request_header_handles_invalid_data() {
80        let data = r#"{"groupName":12345}"#;
81        let result: Result<DeleteSubscriptionGroupRequestHeader, _> = serde_json::from_str(data);
82        assert!(result.is_err());
83    }
84}