File tree Expand file tree Collapse file tree 4 files changed +45
-1
lines changed
internal/mithril-aggregator-client/src Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ mod client;
77mod error;
88mod external_trait_impls;
99pub mod query;
10- #[ cfg( test) ]
1110mod test;
1211
1312pub use builder:: AggregatorClientBuilder ;
Original file line number Diff line number Diff line change 1+ #[ cfg( test) ]
12use httpmock:: MockServer ;
23
4+ #[ cfg( test) ]
35use crate :: AggregatorHttpClient ;
46
57#[ cfg( test) ]
@@ -29,3 +31,36 @@ macro_rules! assert_error_matches {
2931}
3032#[ cfg( test) ]
3133pub ( crate ) use assert_error_matches;
34+
35+ /// Define a test that checks that http compression is enabled for the client.
36+ ///
37+ /// Requires `httpmock` in dev-dependencies
38+ #[ macro_export]
39+ macro_rules! test_http_compression_is_enabled {
40+ ( ) => {
41+ #[ tokio:: test]
42+ async fn test_http_compression_is_enabled_and_send_accept_encoding_header_with_correct_values( ) {
43+ let server = httpmock:: MockServer :: start( ) ;
44+ server. mock( |when, then| {
45+ when. is_true( |req| {
46+ let headers = req. headers( ) ;
47+ let accept_encoding_header = headers
48+ . get( "accept-encoding" )
49+ . expect( "Accept-Encoding header not found" ) ;
50+
51+ [ "gzip" , "br" , "deflate" , "zstd" ] . iter( ) . all( |& encoding| {
52+ accept_encoding_header. to_str( ) . is_ok_and( |h| h. contains( encoding) )
53+ } )
54+ } ) ;
55+
56+ then. status( 200 ) . body( "[]" ) ;
57+ } ) ;
58+
59+ let client = $crate:: AggregatorHttpClient :: builder( server. base_url( ) ) . build( ) . unwrap( ) ;
60+ client
61+ . send( $crate:: query:: GetCertificatesListQuery :: latest( ) )
62+ . await
63+ . expect( "GET request should succeed with Accept-Encoding header" ) ;
64+ }
65+ } ;
66+ }
Original file line number Diff line number Diff line change @@ -69,3 +69,8 @@ use tikv_jemallocator::Jemalloc;
6969#[ cfg( all( not( target_env = "msvc" ) , feature = "jemallocator" ) ) ]
7070#[ global_allocator]
7171static GLOBAL : Jemalloc = Jemalloc ;
72+
73+ #[ cfg( test) ]
74+ mod tests {
75+ mithril_aggregator_client:: test_http_compression_is_enabled!( ) ;
76+ }
Original file line number Diff line number Diff line change @@ -43,3 +43,8 @@ static GLOBAL: Jemalloc = Jemalloc;
4343pub ( crate ) mod test_tools {
4444 mithril_common:: define_test_logger!( ) ;
4545}
46+
47+ #[ cfg( test) ]
48+ mod tests {
49+ mithril_aggregator_client:: test_http_compression_is_enabled!( ) ;
50+ }
You can’t perform that action at this time.
0 commit comments