@@ -308,6 +308,9 @@ fn read_policies_file(path: &Path) -> Result<HashMap<String, Policy>> {
308
308
#[ cfg( test) ]
309
309
mod tests {
310
310
use super :: * ;
311
+ use crate :: cli;
312
+ use std:: io:: Write ;
313
+ use tempfile:: NamedTempFile ;
311
314
312
315
#[ test]
313
316
fn get_settings_when_data_is_provided ( ) {
@@ -460,4 +463,41 @@ example:
460
463
let settings = json_data. unwrap ( ) ;
461
464
assert ! ( settings. is_empty( ) ) ;
462
465
}
466
+
467
+ #[ test]
468
+ fn boolean_flags ( ) {
469
+ let policies_yaml = r#"
470
+ ---
471
+ example:
472
+ url: file:///tmp/namespace-validate-policy.wasm
473
+ settings: {}
474
+ "# ;
475
+ let mut temp_file = NamedTempFile :: new ( ) . unwrap ( ) ;
476
+ temp_file. write_all ( policies_yaml. as_bytes ( ) ) . unwrap ( ) ;
477
+ let file_path = temp_file. into_temp_path ( ) ;
478
+ let policies_flag = format ! ( "--policies={}" , file_path. to_str( ) . unwrap( ) ) ;
479
+
480
+ let boolean_flags = [
481
+ "--enable-pprof" ,
482
+ "--log-no-color" ,
483
+ "--daemon" ,
484
+ "--enable-metrics" ,
485
+ ] ;
486
+
487
+ for provide_flag in [ true , false ] {
488
+ let cli = cli:: build_cli ( ) ;
489
+
490
+ let mut flags = vec ! [ "policy-server" , & policies_flag] ;
491
+ if provide_flag {
492
+ flags. extend ( boolean_flags) ;
493
+ }
494
+
495
+ let matches = cli. clone ( ) . try_get_matches_from ( flags) . unwrap ( ) ;
496
+ let config = Config :: from_args ( & matches) . unwrap ( ) ;
497
+ assert_eq ! ( provide_flag, config. enable_pprof) ;
498
+ assert_eq ! ( provide_flag, config. log_no_color) ;
499
+ assert_eq ! ( provide_flag, config. daemon) ;
500
+ assert_eq ! ( provide_flag, config. metrics_enabled) ;
501
+ }
502
+ }
463
503
}
0 commit comments