@@ -210,173 +210,100 @@ mod tests {
210
210
}
211
211
}
212
212
213
- mod get {
214
- use super :: * ;
215
-
216
- #[ tokio:: test]
217
- async fn test_minimal_get_query ( ) {
218
- let ( server, client) = setup_server_and_client ( ) ;
219
- server. mock ( |when, then| {
220
- when. method ( httpmock:: Method :: GET ) . path ( "/dummy-get-route" ) ;
221
- then. status ( 200 ) . body ( r#"{"foo": "bar", "bar": 123}"# ) ;
222
- } ) ;
223
-
224
- let response = client. send ( TestGetQuery ) . await . unwrap ( ) ;
225
-
226
- assert_eq ! (
227
- response,
228
- TestResponse {
229
- foo: "bar" . to_string( ) ,
230
- bar: 123 ,
231
- }
232
- )
233
- }
234
-
235
- #[ tokio:: test]
236
- async fn test_get_query_send_mithril_api_version_header ( ) {
237
- let ( server, mut client) = setup_server_and_client ( ) ;
238
- client. api_version_provider =
239
- APIVersionProvider :: new_with_default_version ( Version :: parse ( "1.2.9" ) . unwrap ( ) ) ;
240
- server. mock ( |when, then| {
241
- when. method ( httpmock:: Method :: GET )
242
- . header ( MITHRIL_API_VERSION_HEADER , "1.2.9" ) ;
243
- then. status ( 200 ) . body ( r#"{"foo": "a", "bar": 1}"# ) ;
244
- } ) ;
245
-
246
- client. send ( TestGetQuery ) . await . expect ( "should not fail" ) ;
247
- }
248
-
249
- #[ tokio:: test]
250
- async fn test_get_query_send_additional_header_and_dont_override_mithril_api_version_header ( )
251
- {
252
- let ( server, mut client) = setup_server_and_client ( ) ;
253
- client. api_version_provider =
254
- APIVersionProvider :: new_with_default_version ( Version :: parse ( "1.2.9" ) . unwrap ( ) ) ;
255
- client. additional_headers = {
256
- let mut headers = HeaderMap :: new ( ) ;
257
- headers. insert ( MITHRIL_API_VERSION_HEADER , "9.4.5" . parse ( ) . unwrap ( ) ) ;
258
- headers. insert ( "foo" , "bar" . parse ( ) . unwrap ( ) ) ;
259
- headers
260
- } ;
261
-
262
- server. mock ( |when, then| {
263
- when. method ( httpmock:: Method :: GET )
264
- . header ( MITHRIL_API_VERSION_HEADER , "1.2.9" )
265
- . header ( "foo" , "bar" ) ;
266
- then. status ( 200 ) . body ( r#"{"foo": "a", "bar": 1}"# ) ;
267
- } ) ;
268
-
269
- client. send ( TestGetQuery ) . await . expect ( "should not fail" ) ;
270
- }
271
-
272
- #[ tokio:: test]
273
- async fn test_get_query_timeout ( ) {
274
- let ( server, mut client) = setup_server_and_client ( ) ;
275
- client. timeout_duration = Some ( Duration :: from_millis ( 10 ) ) ;
276
- let _server_mock = server. mock ( |when, then| {
277
- when. method ( httpmock:: Method :: GET ) ;
278
- then. delay ( Duration :: from_millis ( 100 ) ) ;
279
- } ) ;
280
-
281
- let error = client. send ( TestGetQuery ) . await . expect_err ( "should not fail" ) ;
282
-
283
- assert ! (
284
- matches!( error, AggregatorClientError :: RemoteServerUnreachable ( _) ) ,
285
- "unexpected error type: {error:?}"
286
- ) ;
287
- }
213
+ #[ tokio:: test]
214
+ async fn test_minimal_get_query ( ) {
215
+ let ( server, client) = setup_server_and_client ( ) ;
216
+ server. mock ( |when, then| {
217
+ when. method ( httpmock:: Method :: GET ) . path ( "/dummy-get-route" ) ;
218
+ then. status ( 200 ) . body ( r#"{"foo": "bar", "bar": 123}"# ) ;
219
+ } ) ;
220
+
221
+ let response = client. send ( TestGetQuery ) . await . unwrap ( ) ;
222
+
223
+ assert_eq ! (
224
+ response,
225
+ TestResponse {
226
+ foo: "bar" . to_string( ) ,
227
+ bar: 123 ,
228
+ }
229
+ )
288
230
}
289
231
290
- mod post {
291
- use super :: * ;
292
-
293
- #[ tokio:: test]
294
- async fn test_minimal_post_query ( ) {
295
- let ( server, client) = setup_server_and_client ( ) ;
296
- server. mock ( |when, then| {
297
- when. method ( httpmock:: Method :: POST )
298
- . path ( "/dummy-post-route" )
299
- . header ( "content-type" , "application/json" )
300
- . body ( serde_json:: to_string ( & TestBody :: new ( "miaouss" , 5 ) ) . unwrap ( ) ) ;
301
- then. status ( 201 ) ;
302
- } ) ;
303
-
304
- client
305
- . send ( TestPostQuery {
306
- body : TestBody :: new ( "miaouss" , 5 ) ,
307
- } )
308
- . await
309
- . unwrap ( ) ;
310
- }
311
-
312
- #[ tokio:: test]
313
- async fn test_post_query_send_mithril_api_version_header ( ) {
314
- let ( server, mut client) = setup_server_and_client ( ) ;
315
- client. api_version_provider =
316
- APIVersionProvider :: new_with_default_version ( Version :: parse ( "1.2.9" ) . unwrap ( ) ) ;
317
- server. mock ( |when, then| {
318
- when. method ( httpmock:: Method :: POST )
319
- . header ( MITHRIL_API_VERSION_HEADER , "1.2.9" ) ;
320
- then. status ( 201 ) ;
321
- } ) ;
322
-
323
- client
324
- . send ( TestPostQuery {
325
- body : TestBody :: new ( "miaouss" , 3 ) ,
326
- } )
327
- . await
328
- . expect ( "should not fail" ) ;
329
- }
330
-
331
- #[ tokio:: test]
332
- async fn test_post_query_send_additional_header_and_dont_override_mithril_api_version_header ( )
333
- {
334
- let ( server, mut client) = setup_server_and_client ( ) ;
335
- client. api_version_provider =
336
- APIVersionProvider :: new_with_default_version ( Version :: parse ( "1.2.9" ) . unwrap ( ) ) ;
337
- client. additional_headers = {
338
- let mut headers = HeaderMap :: new ( ) ;
339
- headers. insert ( MITHRIL_API_VERSION_HEADER , "9.4.5" . parse ( ) . unwrap ( ) ) ;
340
- headers. insert ( "foo" , "bar" . parse ( ) . unwrap ( ) ) ;
341
- headers
342
- } ;
343
-
344
- server. mock ( |when, then| {
345
- when. method ( httpmock:: Method :: POST )
346
- . header ( MITHRIL_API_VERSION_HEADER , "1.2.9" )
347
- . header ( "foo" , "bar" ) ;
348
- then. status ( 201 ) . body ( r#"{"foo": "a", "bar": 1}"# ) ;
349
- } ) ;
350
-
351
- client
352
- . send ( TestPostQuery {
353
- body : TestBody :: new ( "miaouss" , 3 ) ,
354
- } )
355
- . await
356
- . expect ( "should not fail" ) ;
357
- }
232
+ #[ tokio:: test]
233
+ async fn test_minimal_post_query ( ) {
234
+ let ( server, client) = setup_server_and_client ( ) ;
235
+ server. mock ( |when, then| {
236
+ when. method ( httpmock:: Method :: POST )
237
+ . path ( "/dummy-post-route" )
238
+ . header ( "content-type" , "application/json" )
239
+ . body ( serde_json:: to_string ( & TestBody :: new ( "miaouss" , 5 ) ) . unwrap ( ) ) ;
240
+ then. status ( 201 ) ;
241
+ } ) ;
242
+
243
+ client
244
+ . send ( TestPostQuery {
245
+ body : TestBody :: new ( "miaouss" , 5 ) ,
246
+ } )
247
+ . await
248
+ . unwrap ( ) ;
249
+ }
358
250
359
- #[ tokio:: test]
360
- async fn test_post_query_timeout ( ) {
361
- let ( server, mut client) = setup_server_and_client ( ) ;
362
- client. timeout_duration = Some ( Duration :: from_millis ( 10 ) ) ;
363
- let _server_mock = server. mock ( |when, then| {
364
- when. method ( httpmock:: Method :: POST ) ;
365
- then. delay ( Duration :: from_millis ( 100 ) ) ;
366
- } ) ;
251
+ #[ tokio:: test]
252
+ async fn test_query_send_mithril_api_version_header ( ) {
253
+ let ( server, mut client) = setup_server_and_client ( ) ;
254
+ client. api_version_provider =
255
+ APIVersionProvider :: new_with_default_version ( Version :: parse ( "1.2.9" ) . unwrap ( ) ) ;
256
+ server. mock ( |when, then| {
257
+ when. method ( httpmock:: Method :: GET )
258
+ . header ( MITHRIL_API_VERSION_HEADER , "1.2.9" ) ;
259
+ then. status ( 200 ) . body ( r#"{"foo": "a", "bar": 1}"# ) ;
260
+ } ) ;
261
+
262
+ client. send ( TestGetQuery ) . await . expect ( "should not fail" ) ;
263
+ }
367
264
368
- let error = client
369
- . send ( TestPostQuery {
370
- body : TestBody :: new ( "miaouss" , 3 ) ,
371
- } )
372
- . await
373
- . expect_err ( "should not fail" ) ;
265
+ #[ tokio:: test]
266
+ async fn test_query_send_additional_header_and_dont_override_mithril_api_version_header ( ) {
267
+ let ( server, mut client) = setup_server_and_client ( ) ;
268
+ client. api_version_provider =
269
+ APIVersionProvider :: new_with_default_version ( Version :: parse ( "1.2.9" ) . unwrap ( ) ) ;
270
+ client. additional_headers = {
271
+ let mut headers = HeaderMap :: new ( ) ;
272
+ headers. insert ( MITHRIL_API_VERSION_HEADER , "9.4.5" . parse ( ) . unwrap ( ) ) ;
273
+ headers. insert ( "foo" , "bar" . parse ( ) . unwrap ( ) ) ;
274
+ headers
275
+ } ;
276
+
277
+ server. mock ( |when, then| {
278
+ when. method ( httpmock:: Method :: POST )
279
+ . header ( MITHRIL_API_VERSION_HEADER , "1.2.9" )
280
+ . header ( "foo" , "bar" ) ;
281
+ then. status ( 201 ) . body ( r#"{"foo": "a", "bar": 1}"# ) ;
282
+ } ) ;
283
+
284
+ client
285
+ . send ( TestPostQuery {
286
+ body : TestBody :: new ( "miaouss" , 3 ) ,
287
+ } )
288
+ . await
289
+ . expect ( "should not fail" ) ;
290
+ }
374
291
375
- assert ! (
376
- matches!( error, AggregatorClientError :: RemoteServerUnreachable ( _) ) ,
377
- "unexpected error type: {error:?}"
378
- ) ;
379
- }
292
+ #[ tokio:: test]
293
+ async fn test_query_timeout ( ) {
294
+ let ( server, mut client) = setup_server_and_client ( ) ;
295
+ client. timeout_duration = Some ( Duration :: from_millis ( 10 ) ) ;
296
+ let _server_mock = server. mock ( |when, then| {
297
+ when. method ( httpmock:: Method :: GET ) ;
298
+ then. delay ( Duration :: from_millis ( 100 ) ) ;
299
+ } ) ;
300
+
301
+ let error = client. send ( TestGetQuery ) . await . expect_err ( "should not fail" ) ;
302
+
303
+ assert ! (
304
+ matches!( error, AggregatorClientError :: RemoteServerUnreachable ( _) ) ,
305
+ "unexpected error type: {error:?}"
306
+ ) ;
380
307
}
381
308
382
309
mod warn_if_api_version_mismatch {
@@ -529,33 +456,7 @@ mod tests {
529
456
}
530
457
531
458
#[ tokio:: test]
532
- async fn test_client_get_log_warning_if_api_version_mismatch ( ) {
533
- let aggregator_version = "2.0.0" ;
534
- let client_version = "1.0.0" ;
535
- let ( server, mut client) = setup_server_and_client ( ) ;
536
- let ( logger, log_inspector) = TestLogger :: memory ( ) ;
537
- client. api_version_provider = APIVersionProvider :: new_with_default_version (
538
- Version :: parse ( client_version) . unwrap ( ) ,
539
- ) ;
540
- client. logger = logger;
541
- server. mock ( |_, then| {
542
- then. status ( StatusCode :: OK . as_u16 ( ) )
543
- . header ( MITHRIL_API_VERSION_HEADER , aggregator_version)
544
- . body ( r#"{"foo": "bar", "bar": 123}"# ) ;
545
- } ) ;
546
-
547
- assert ! (
548
- Version :: parse( aggregator_version) . unwrap( )
549
- > Version :: parse( client_version) . unwrap( )
550
- ) ;
551
-
552
- client. send ( TestGetQuery ) . await . unwrap ( ) ;
553
-
554
- assert_api_version_warning_logged ( & log_inspector, aggregator_version, client_version) ;
555
- }
556
-
557
- #[ tokio:: test]
558
- async fn test_client_post_log_warning_if_api_version_mismatch ( ) {
459
+ async fn test_client_log_warning_if_api_version_mismatch ( ) {
559
460
let aggregator_version = "2.0.0" ;
560
461
let client_version = "1.0.0" ;
561
462
let ( server, mut client) = setup_server_and_client ( ) ;
0 commit comments