openstack_sdk/api/block_storage/v3/version/
get.rs1use 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 pub fn builder() -> RequestBuilder {
34 RequestBuilder::default()
35 }
36}
37
38impl RequestBuilder {
39 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 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 "".to_string().into()
70 }
71
72 fn parameters(&self) -> QueryParams {
73 QueryParams::default()
74 }
75
76 fn service_type(&self) -> ServiceType {
77 ServiceType::BlockStorage
78 }
79
80 fn response_key(&self) -> Option<Cow<'static, str>> {
81 None
82 }
83
84 fn request_headers(&self) -> Option<&HeaderMap> {
86 self._headers.as_ref()
87 }
88
89 fn api_version(&self) -> Option<ApiVersion> {
91 Some(ApiVersion::new(3, 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::BlockStorage
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).path("/".to_string());
126
127 then.status(200)
128 .header("content-type", "application/json")
129 .json_body(json!({ "dummy": {} }));
130 });
131
132 let endpoint = Request::builder().build().unwrap();
133 let _: serde_json::Value = endpoint.query(&client).unwrap();
134 mock.assert();
135 }
136
137 #[cfg(feature = "sync")]
138 #[test]
139 fn endpoint_headers() {
140 let server = MockServer::start();
141 let client = FakeOpenStackClient::new(server.base_url());
142 let mock = server.mock(|when, then| {
143 when.method(httpmock::Method::GET)
144 .path("/".to_string())
145 .header("foo", "bar")
146 .header("not_foo", "not_bar");
147 then.status(200)
148 .header("content-type", "application/json")
149 .json_body(json!({ "dummy": {} }));
150 });
151
152 let endpoint = Request::builder()
153 .headers(
154 [(
155 Some(HeaderName::from_static("foo")),
156 HeaderValue::from_static("bar"),
157 )]
158 .into_iter(),
159 )
160 .header("not_foo", "not_bar")
161 .build()
162 .unwrap();
163 let _: serde_json::Value = endpoint.query(&client).unwrap();
164 mock.assert();
165 }
166}