@@ -464,4 +464,76 @@ mod test {
464464 Some ( ( Bandwidth :: from_bps( 12132938 ) , Duration :: from_millis( 100 ) ) )
465465 ) ;
466466 }
467+
468+ #[ test]
469+ #[ cfg( feature = "human" ) ]
470+ fn test_compatibility_with_figment ( ) {
471+ use figment:: {
472+ providers:: { Format , Json } ,
473+ Figment ,
474+ } ;
475+
476+ let config = r##"
477+ {
478+ "RepeatedBwPatternConfig": {
479+ "pattern": [
480+ {"TraceBwConfig": [["25ms",["10Mbps", "20Mbps"]],["2ms",["11Mbps", "23Mbps"]]]},
481+ {"SawtoothBwConfig": {
482+ "bottom" : "10Mbps",
483+ "top" : "20Mbps",
484+ "step" : "1ms",
485+ "interval" : "10ms",
486+ "duty_ratio" : 0.5
487+ }
488+ }
489+ ],
490+ "count": 0
491+ }
492+ }
493+ "## ;
494+
495+ let trace: Box < dyn BwTraceConfig > = Figment :: new ( )
496+ . merge ( Json :: string ( config) )
497+ . extract ( )
498+ . unwrap ( ) ;
499+
500+ let mut model = trace. into_model ( ) ;
501+
502+ assert_eq ! (
503+ model. next_bw( ) ,
504+ Some ( ( Bandwidth :: from_mbps( 10 ) , Duration :: from_millis( 25 ) ) )
505+ ) ;
506+ assert_eq ! (
507+ model. next_bw( ) ,
508+ Some ( ( Bandwidth :: from_mbps( 20 ) , Duration :: from_millis( 25 ) ) )
509+ ) ;
510+ assert_eq ! (
511+ model. next_bw( ) ,
512+ Some ( ( Bandwidth :: from_mbps( 11 ) , Duration :: from_millis( 2 ) ) )
513+ ) ;
514+ assert_eq ! (
515+ model. next_bw( ) ,
516+ Some ( ( Bandwidth :: from_mbps( 23 ) , Duration :: from_millis( 2 ) ) )
517+ ) ;
518+ assert_eq ! (
519+ model. next_bw( ) ,
520+ Some ( ( Bandwidth :: from_mbps( 10 ) , Duration :: from_millis( 1 ) ) )
521+ ) ;
522+ assert_eq ! (
523+ model. next_bw( ) ,
524+ Some ( ( Bandwidth :: from_mbps( 12 ) , Duration :: from_millis( 1 ) ) )
525+ ) ;
526+ assert_eq ! (
527+ model. next_bw( ) ,
528+ Some ( ( Bandwidth :: from_mbps( 14 ) , Duration :: from_millis( 1 ) ) )
529+ ) ;
530+ assert_eq ! (
531+ model. next_bw( ) ,
532+ Some ( ( Bandwidth :: from_mbps( 16 ) , Duration :: from_millis( 1 ) ) )
533+ ) ;
534+ assert_eq ! (
535+ model. next_bw( ) ,
536+ Some ( ( Bandwidth :: from_mbps( 18 ) , Duration :: from_millis( 1 ) ) )
537+ ) ;
538+ }
467539}
0 commit comments