Skip to main content

openstack_sdk_identity/v3/limit/model/
head.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//! Retrieve enforcement model.
19//!
20//! GET /v3/limits/model
21//!
22use derive_builder::Builder;
23use http::{HeaderMap, HeaderName, HeaderValue};
24
25use openstack_sdk_core::api::rest_endpoint_prelude::*;
26
27#[derive(Builder, Debug, Clone)]
28#[builder(setter(strip_option))]
29pub struct Request {
30    #[builder(setter(name = "_headers"), default, private)]
31    _headers: Option<HeaderMap>,
32}
33impl Request {
34    /// Create a builder for the endpoint.
35    pub fn builder() -> RequestBuilder {
36        RequestBuilder::default()
37    }
38}
39
40impl RequestBuilder {
41    /// Add a single header to the Model.
42    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
43    where
44        K: Into<HeaderName>,
45        V: Into<HeaderValue>,
46    {
47        self._headers
48            .get_or_insert(None)
49            .get_or_insert_with(HeaderMap::new)
50            .insert(header_name.into(), header_value.into());
51        self
52    }
53
54    /// Add multiple headers.
55    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
56    where
57        I: Iterator<Item = T>,
58        T: Into<(Option<HeaderName>, HeaderValue)>,
59    {
60        self._headers
61            .get_or_insert(None)
62            .get_or_insert_with(HeaderMap::new)
63            .extend(iter.map(Into::into));
64        self
65    }
66}
67
68impl RestEndpoint for Request {
69    fn method(&self) -> http::Method {
70        http::Method::HEAD
71    }
72
73    fn endpoint(&self) -> Cow<'static, str> {
74        "limits/model".to_string().into()
75    }
76
77    fn parameters(&self) -> QueryParams<'_> {
78        QueryParams::default()
79    }
80
81    fn service_type(&self) -> ServiceType {
82        ServiceType::Identity
83    }
84
85    fn response_key(&self) -> Option<Cow<'static, str>> {
86        None
87    }
88
89    /// Returns headers to be set into the request
90    fn request_headers(&self) -> Option<&HeaderMap> {
91        self._headers.as_ref()
92    }
93
94    /// Returns required API version
95    fn api_version(&self) -> Option<ApiVersion> {
96        Some(ApiVersion::new(3, 0))
97    }
98}
99
100#[cfg(test)]
101mod tests {
102    use super::*;
103    use http::{HeaderName, HeaderValue};
104    use httpmock::MockServer;
105    #[cfg(feature = "sync")]
106    use openstack_sdk_core::api::RawQuery;
107    use openstack_sdk_core::test::client::FakeOpenStackClient;
108    use openstack_sdk_core::types::ServiceType;
109
110    #[test]
111    fn test_service_type() {
112        assert_eq!(
113            Request::builder().build().unwrap().service_type(),
114            ServiceType::Identity
115        );
116    }
117
118    #[test]
119    fn test_response_key() {
120        assert!(Request::builder().build().unwrap().response_key().is_none())
121    }
122
123    #[cfg(feature = "sync")]
124    #[test]
125    fn endpoint() {
126        let server = MockServer::start();
127        let client = FakeOpenStackClient::new(server.base_url());
128        let mock = server.mock(|when, then| {
129            when.method(httpmock::Method::HEAD)
130                .path("/limits/model".to_string());
131
132            then.status(200).header("content-type", "application/json");
133        });
134
135        let endpoint = Request::builder().build().unwrap();
136        let _ = endpoint.raw_query(&client).unwrap();
137        mock.assert();
138    }
139
140    #[cfg(feature = "sync")]
141    #[test]
142    fn endpoint_headers() {
143        let server = MockServer::start();
144        let client = FakeOpenStackClient::new(server.base_url());
145        let mock = server.mock(|when, then| {
146            when.method(httpmock::Method::HEAD)
147                .path("/limits/model".to_string())
148                .header("foo", "bar")
149                .header("not_foo", "not_bar");
150            then.status(200).header("content-type", "application/json");
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(
162                HeaderName::from_static("not_foo"),
163                HeaderValue::from_static("not_bar"),
164            )
165            .build()
166            .unwrap();
167        let _ = endpoint.raw_query(&client).unwrap();
168        mock.assert();
169    }
170}