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