openstack_sdk/api/dns/v2/limit/
get.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14//
15// WARNING: This file is automatically generated from OpenAPI schema using
16// `openstack-codegenerator`.
17
18//! List project limits
19//!
20use derive_builder::Builder;
21use http::{HeaderMap, HeaderName, HeaderValue};
22
23use crate::api::rest_endpoint_prelude::*;
24
25#[derive(Builder, Debug, Clone)]
26#[builder(setter(strip_option))]
27pub struct Request {
28    #[builder(setter(name = "_headers"), default, private)]
29    _headers: Option<HeaderMap>,
30}
31impl Request {
32    /// Create a builder for the endpoint.
33    pub fn builder() -> RequestBuilder {
34        RequestBuilder::default()
35    }
36}
37
38impl RequestBuilder {
39    /// Add a single header to the Limit.
40    pub fn header(&mut self, header_name: &'static str, header_value: &'static str) -> &mut Self
41where {
42        self._headers
43            .get_or_insert(None)
44            .get_or_insert_with(HeaderMap::new)
45            .insert(header_name, HeaderValue::from_static(header_value));
46        self
47    }
48
49    /// Add multiple headers.
50    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
51    where
52        I: Iterator<Item = T>,
53        T: Into<(Option<HeaderName>, HeaderValue)>,
54    {
55        self._headers
56            .get_or_insert(None)
57            .get_or_insert_with(HeaderMap::new)
58            .extend(iter.map(Into::into));
59        self
60    }
61}
62
63impl RestEndpoint for Request {
64    fn method(&self) -> http::Method {
65        http::Method::GET
66    }
67
68    fn endpoint(&self) -> Cow<'static, str> {
69        "limits".to_string().into()
70    }
71
72    fn parameters(&self) -> QueryParams {
73        QueryParams::default()
74    }
75
76    fn service_type(&self) -> ServiceType {
77        ServiceType::Dns
78    }
79
80    fn response_key(&self) -> Option<Cow<'static, str>> {
81        None
82    }
83
84    /// Returns headers to be set into the request
85    fn request_headers(&self) -> Option<&HeaderMap> {
86        self._headers.as_ref()
87    }
88
89    /// Returns required API version
90    fn api_version(&self) -> Option<ApiVersion> {
91        Some(ApiVersion::new(2, 0))
92    }
93}
94
95#[cfg(test)]
96mod tests {
97    use super::*;
98    #[cfg(feature = "sync")]
99    use crate::api::Query;
100    use crate::test::client::FakeOpenStackClient;
101    use crate::types::ServiceType;
102    use http::{HeaderName, HeaderValue};
103    use httpmock::MockServer;
104    use serde_json::json;
105
106    #[test]
107    fn test_service_type() {
108        assert_eq!(
109            Request::builder().build().unwrap().service_type(),
110            ServiceType::Dns
111        );
112    }
113
114    #[test]
115    fn test_response_key() {
116        assert!(Request::builder().build().unwrap().response_key().is_none())
117    }
118
119    #[cfg(feature = "sync")]
120    #[test]
121    fn endpoint() {
122        let server = MockServer::start();
123        let client = FakeOpenStackClient::new(server.base_url());
124        let mock = server.mock(|when, then| {
125            when.method(httpmock::Method::GET)
126                .path("/limits".to_string());
127
128            then.status(200)
129                .header("content-type", "application/json")
130                .json_body(json!({ "dummy": {} }));
131        });
132
133        let endpoint = Request::builder().build().unwrap();
134        let _: serde_json::Value = endpoint.query(&client).unwrap();
135        mock.assert();
136    }
137
138    #[cfg(feature = "sync")]
139    #[test]
140    fn endpoint_headers() {
141        let server = MockServer::start();
142        let client = FakeOpenStackClient::new(server.base_url());
143        let mock = server.mock(|when, then| {
144            when.method(httpmock::Method::GET)
145                .path("/limits".to_string())
146                .header("foo", "bar")
147                .header("not_foo", "not_bar");
148            then.status(200)
149                .header("content-type", "application/json")
150                .json_body(json!({ "dummy": {} }));
151        });
152
153        let endpoint = Request::builder()
154            .headers(
155                [(
156                    Some(HeaderName::from_static("foo")),
157                    HeaderValue::from_static("bar"),
158                )]
159                .into_iter(),
160            )
161            .header("not_foo", "not_bar")
162            .build()
163            .unwrap();
164        let _: serde_json::Value = endpoint.query(&client).unwrap();
165        mock.assert();
166    }
167}