openstack_sdk_load_balancer/v2/quota/
list.rs1use derive_builder::Builder;
36use http::{HeaderMap, HeaderName, HeaderValue};
37
38use openstack_sdk_core::api::rest_endpoint_prelude::*;
39
40#[derive(Builder, Debug, Clone)]
41#[builder(setter(strip_option))]
42pub struct Request {
43 #[builder(setter(name = "_headers"), default, private)]
44 _headers: Option<HeaderMap>,
45}
46impl Request {
47 pub fn builder() -> RequestBuilder {
49 RequestBuilder::default()
50 }
51}
52
53impl RequestBuilder {
54 pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
56 where
57 K: Into<HeaderName>,
58 V: Into<HeaderValue>,
59 {
60 self._headers
61 .get_or_insert(None)
62 .get_or_insert_with(HeaderMap::new)
63 .insert(header_name.into(), header_value.into());
64 self
65 }
66
67 pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
69 where
70 I: Iterator<Item = T>,
71 T: Into<(Option<HeaderName>, HeaderValue)>,
72 {
73 self._headers
74 .get_or_insert(None)
75 .get_or_insert_with(HeaderMap::new)
76 .extend(iter.map(Into::into));
77 self
78 }
79}
80
81impl RestEndpoint for Request {
82 fn method(&self) -> http::Method {
83 http::Method::GET
84 }
85
86 fn endpoint(&self) -> Cow<'static, str> {
87 "lbaas/quotas".to_string().into()
88 }
89
90 fn parameters(&self) -> QueryParams<'_> {
91 QueryParams::default()
92 }
93
94 fn service_type(&self) -> ServiceType {
95 ServiceType::LoadBalancer
96 }
97
98 fn response_key(&self) -> Option<Cow<'static, str>> {
99 Some("quotas".into())
100 }
101
102 fn request_headers(&self) -> Option<&HeaderMap> {
104 self._headers.as_ref()
105 }
106
107 fn api_version(&self) -> Option<ApiVersion> {
109 Some(ApiVersion::new(2, 0))
110 }
111}
112
113#[cfg(test)]
114mod tests {
115 use super::*;
116 use http::{HeaderName, HeaderValue};
117 use httpmock::MockServer;
118 #[cfg(feature = "sync")]
119 use openstack_sdk_core::api::Query;
120 use openstack_sdk_core::test::client::FakeOpenStackClient;
121 use openstack_sdk_core::types::ServiceType;
122 use serde_json::json;
123
124 #[test]
125 fn test_service_type() {
126 assert_eq!(
127 Request::builder().build().unwrap().service_type(),
128 ServiceType::LoadBalancer
129 );
130 }
131
132 #[test]
133 fn test_response_key() {
134 assert_eq!(
135 Request::builder().build().unwrap().response_key().unwrap(),
136 "quotas"
137 );
138 }
139
140 #[cfg(feature = "sync")]
141 #[test]
142 fn endpoint() {
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::GET)
147 .path("/lbaas/quotas".to_string());
148
149 then.status(200)
150 .header("content-type", "application/json")
151 .json_body(json!({ "quotas": {} }));
152 });
153
154 let endpoint = Request::builder().build().unwrap();
155 let _: serde_json::Value = endpoint.query(&client).unwrap();
156 mock.assert();
157 }
158
159 #[cfg(feature = "sync")]
160 #[test]
161 fn endpoint_headers() {
162 let server = MockServer::start();
163 let client = FakeOpenStackClient::new(server.base_url());
164 let mock = server.mock(|when, then| {
165 when.method(httpmock::Method::GET)
166 .path("/lbaas/quotas".to_string())
167 .header("foo", "bar")
168 .header("not_foo", "not_bar");
169 then.status(200)
170 .header("content-type", "application/json")
171 .json_body(json!({ "quotas": {} }));
172 });
173
174 let endpoint = Request::builder()
175 .headers(
176 [(
177 Some(HeaderName::from_static("foo")),
178 HeaderValue::from_static("bar"),
179 )]
180 .into_iter(),
181 )
182 .header(
183 HeaderName::from_static("not_foo"),
184 HeaderValue::from_static("not_bar"),
185 )
186 .build()
187 .unwrap();
188 let _: serde_json::Value = endpoint.query(&client).unwrap();
189 mock.assert();
190 }
191}