@@ -296,4 +296,64 @@ mod tests {
296296 let pooled = ConcurrencyStrategy :: new ( None , false ) ;
297297 assert_eq ! ( pooled. connection_count( ) , 1 ) ;
298298 }
299+
300+ mod throttle_config_parsing {
301+ use crate :: generator:: common:: BytesThrottleConfig ;
302+ use serde_yaml:: with:: singleton_map_recursive;
303+
304+ /// Helper to deserialize ThrottleConfig using singleton_map_recursive
305+ /// (matches how the main config deserializes it)
306+ fn parse_throttle_config ( yaml : & str ) -> BytesThrottleConfig {
307+ let value: serde_yaml:: Value = serde_yaml:: from_str ( yaml) . unwrap ( ) ;
308+ singleton_map_recursive:: deserialize ( value) . unwrap ( )
309+ }
310+
311+ #[ test]
312+ fn parse_all_out ( ) {
313+ let yaml = r#"all_out"# ;
314+ let config = parse_throttle_config ( yaml) ;
315+ assert ! ( matches!( config, BytesThrottleConfig :: AllOut ) ) ;
316+ }
317+
318+ #[ test]
319+ fn parse_stable_bytes_per_second ( ) {
320+ let yaml = r#"
321+ stable:
322+ bytes_per_second: "10 MiB"
323+ timeout_millis: 100
324+ "# ;
325+ let config = parse_throttle_config ( yaml) ;
326+ assert ! ( matches!( config, BytesThrottleConfig :: Stable { .. } ) ) ;
327+ if let BytesThrottleConfig :: Stable {
328+ bytes_per_second,
329+ timeout_millis,
330+ } = config
331+ {
332+ assert_eq ! ( timeout_millis, 100 ) ;
333+ assert_eq ! ( bytes_per_second. as_u64( ) , 10 * 1024 * 1024 ) ;
334+ }
335+ }
336+
337+ #[ test]
338+ fn parse_linear_bytes_per_second ( ) {
339+ let yaml = r#"
340+ linear:
341+ initial_bytes_per_second: "10 MiB"
342+ maximum_bytes_per_second: "100 MiB"
343+ rate_of_change: "1 MiB"
344+ "# ;
345+ let config = parse_throttle_config ( yaml) ;
346+ assert ! ( matches!( config, BytesThrottleConfig :: Linear { .. } ) ) ;
347+ if let BytesThrottleConfig :: Linear {
348+ initial_bytes_per_second,
349+ maximum_bytes_per_second,
350+ rate_of_change,
351+ } = config
352+ {
353+ assert_eq ! ( initial_bytes_per_second. as_u64( ) , 10 * 1024 * 1024 ) ;
354+ assert_eq ! ( maximum_bytes_per_second. as_u64( ) , 100 * 1024 * 1024 ) ;
355+ assert_eq ! ( rate_of_change. as_u64( ) , 1 * 1024 * 1024 ) ;
356+ }
357+ }
358+ }
299359}
0 commit comments