@@ -29,10 +29,13 @@ impl AggregatorClient {
29
29
}
30
30
31
31
pub async fn send < Q : AggregatorQuery > ( & self , query : Q ) -> AggregatorClientResult < Q :: Response > {
32
+ // Todo: error handling ? Reuse the version in `warn_if_api_version_mismatch` ?
33
+ let current_api_version = self . api_version_provider . compute_current_version ( ) . unwrap ( ) ;
32
34
let mut request_builder = match Q :: method ( ) {
33
35
QueryMethod :: Get => self . client . get ( self . join_aggregator_endpoint ( & query. route ( ) ) ?) ,
34
36
QueryMethod :: Post => self . client . post ( self . join_aggregator_endpoint ( & query. route ( ) ) ?) ,
35
- } ;
37
+ }
38
+ . header ( MITHRIL_API_VERSION_HEADER , current_api_version. to_string ( ) ) ;
36
39
37
40
if let Some ( body) = query. body ( ) {
38
41
request_builder = request_builder. json ( & body) ;
@@ -209,6 +212,20 @@ mod tests {
209
212
}
210
213
)
211
214
}
215
+
216
+ #[ tokio:: test]
217
+ async fn test_get_query_send_mithril_api_version_header ( ) {
218
+ let ( server, mut client) = setup_server_and_client ( ) ;
219
+ client. api_version_provider =
220
+ APIVersionProvider :: new_with_default_version ( Version :: parse ( "1.2.9" ) . unwrap ( ) ) ;
221
+ server. mock ( |when, then| {
222
+ when. method ( httpmock:: Method :: GET )
223
+ . header ( MITHRIL_API_VERSION_HEADER , "1.2.9" ) ;
224
+ then. status ( 200 ) . body ( r#"{"foo": "a", "bar": 1}"# ) ;
225
+ } ) ;
226
+
227
+ client. send ( TestGetQuery ) . await . expect ( "should not fail" ) ;
228
+ }
212
229
}
213
230
214
231
mod post {
@@ -243,13 +260,34 @@ mod tests {
243
260
244
261
assert_eq ! ( response, ( ) )
245
262
}
263
+
264
+ #[ tokio:: test]
265
+ async fn test_post_query_send_mithril_api_version_header ( ) {
266
+ let ( server, mut client) = setup_server_and_client ( ) ;
267
+ client. api_version_provider =
268
+ APIVersionProvider :: new_with_default_version ( Version :: parse ( "1.2.9" ) . unwrap ( ) ) ;
269
+ server. mock ( |when, then| {
270
+ when. method ( httpmock:: Method :: POST )
271
+ . header ( MITHRIL_API_VERSION_HEADER , "1.2.9" ) ;
272
+ then. status ( 201 ) ;
273
+ } ) ;
274
+
275
+ client
276
+ . send ( TestPostQuery {
277
+ body : TestBody {
278
+ pika : "a" . to_string ( ) ,
279
+ chu : 3 ,
280
+ } ,
281
+ } )
282
+ . await
283
+ . expect ( "should not fail" ) ;
284
+ }
246
285
}
247
286
248
287
mod warn_if_api_version_mismatch {
249
288
use http:: response:: Builder as HttpResponseBuilder ;
250
289
use reqwest:: Response ;
251
290
252
- use mithril_common:: test:: api_version_extensions:: ApiVersionProviderExtensions ;
253
291
use mithril_common:: test:: logging:: MemoryDrainForTestInspector ;
254
292
255
293
use super :: * ;
0 commit comments