openstack_sdk/api/network/v2/auto_allocated_topology/
delete.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//! Deletes the auto allocated topology.
19//!
20//! Normal response codes: 204
21//!
22//! Error response codes: 401, 403, 404
23//!
24use derive_builder::Builder;
25use http::{HeaderMap, HeaderName, HeaderValue};
26
27use crate::api::rest_endpoint_prelude::*;
28
29use std::borrow::Cow;
30
31#[derive(Builder, Debug, Clone)]
32#[builder(setter(strip_option))]
33pub struct Request<'a> {
34    /// id parameter for /v2.0/auto-allocated-topology/{id} API
35    #[builder(default, setter(into))]
36    id: Cow<'a, str>,
37
38    #[builder(setter(name = "_headers"), default, private)]
39    _headers: Option<HeaderMap>,
40}
41impl<'a> Request<'a> {
42    /// Create a builder for the endpoint.
43    pub fn builder() -> RequestBuilder<'a> {
44        RequestBuilder::default()
45    }
46}
47
48impl RequestBuilder<'_> {
49    /// Add a single header to the Auto_Allocated_Topology.
50    pub fn header(&mut self, header_name: &'static str, header_value: &'static str) -> &mut Self
51where {
52        self._headers
53            .get_or_insert(None)
54            .get_or_insert_with(HeaderMap::new)
55            .insert(header_name, HeaderValue::from_static(header_value));
56        self
57    }
58
59    /// Add multiple headers.
60    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!("auto-allocated-topology/{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::Network
88    }
89
90    fn response_key(&self) -> Option<Cow<'static, str>> {
91        None
92    }
93
94    /// Returns headers to be set into the request
95    fn request_headers(&self) -> Option<&HeaderMap> {
96        self._headers.as_ref()
97    }
98
99    /// Returns required API version
100    fn api_version(&self) -> Option<ApiVersion> {
101        Some(ApiVersion::new(2, 0))
102    }
103}
104
105#[cfg(test)]
106mod tests {
107    use super::*;
108    #[cfg(feature = "sync")]
109    use crate::api::Query;
110    use crate::test::client::FakeOpenStackClient;
111    use crate::types::ServiceType;
112    use http::{HeaderName, HeaderValue};
113    use httpmock::MockServer;
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::Network
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!("/auto-allocated-topology/{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!("/auto-allocated-topology/{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("not_foo", "not_bar")
173            .build()
174            .unwrap();
175        let _: serde_json::Value = endpoint.query(&client).unwrap();
176        mock.assert();
177    }
178}