@@ -322,193 +322,3 @@ impl ServeCommand {
322322        Ok ( ( ) ) 
323323    } 
324324} 
325- 
326- #[ cfg( test) ]  
327- mod  tests { 
328-     use  config:: ValueKind ; 
329- 
330-     use  super :: * ; 
331-     use  std:: collections:: HashMap ; 
332- 
333-     // TODO : just here to check there is no regression with the old configuration. 
334-     // We may remove it and probably all tests in this file when macros are finished 
335-     impl  ServeCommand  { 
336-         fn  collect_legacy ( & self )  -> Result < Map < String ,  Value > ,  config:: ConfigError >  { 
337-             let  mut  result = Map :: new ( ) ; 
338-             let  namespace = "clap arguments" . to_string ( ) ; 
339- 
340-             if  let  Some ( server_ip)  = self . server_ip . clone ( )  { 
341-                 result. insert ( 
342-                     "server_ip" . to_string ( ) , 
343-                     Value :: new ( Some ( & namespace) ,  ValueKind :: from ( server_ip) ) , 
344-                 ) ; 
345-             } 
346-             if  let  Some ( server_port)  = self . server_port  { 
347-                 result. insert ( 
348-                     "server_port" . to_string ( ) , 
349-                     Value :: new ( Some ( & namespace) ,  ValueKind :: from ( server_port) ) , 
350-                 ) ; 
351-             } 
352-             if  let  Some ( snapshot_directory)  = self . snapshot_directory . clone ( )  { 
353-                 result. insert ( 
354-                     "snapshot_directory" . to_string ( ) , 
355-                     Value :: new ( 
356-                         Some ( & namespace) , 
357-                         ValueKind :: from ( format ! ( "{}" ,  snapshot_directory. to_string_lossy( ) ) ) , 
358-                     ) , 
359-                 ) ; 
360-             } 
361-             if  self . disable_digests_cache  { 
362-                 result. insert ( 
363-                     "disable_digests_cache" . to_string ( ) , 
364-                     Value :: new ( Some ( & namespace) ,  ValueKind :: from ( true ) ) , 
365-                 ) ; 
366-             } ; 
367-             if  self . reset_digests_cache  { 
368-                 result. insert ( 
369-                     "reset_digests_cache" . to_string ( ) , 
370-                     Value :: new ( Some ( & namespace) ,  ValueKind :: from ( true ) ) , 
371-                 ) ; 
372-             } 
373-             if  self . allow_unparsable_block  { 
374-                 result. insert ( 
375-                     "allow_unparsable_block" . to_string ( ) , 
376-                     Value :: new ( Some ( & namespace) ,  ValueKind :: from ( true ) ) , 
377-                 ) ; 
378-             } ; 
379-             if  self . enable_metrics_server  { 
380-                 result. insert ( 
381-                     "enable_metrics_server" . to_string ( ) , 
382-                     Value :: new ( Some ( & namespace) ,  ValueKind :: from ( true ) ) , 
383-                 ) ; 
384-             } ; 
385-             if  let  Some ( metrics_server_ip)  = self . metrics_server_ip . clone ( )  { 
386-                 result. insert ( 
387-                     "metrics_server_ip" . to_string ( ) , 
388-                     Value :: new ( Some ( & namespace) ,  ValueKind :: from ( metrics_server_ip) ) , 
389-                 ) ; 
390-             } 
391-             if  let  Some ( metrics_server_port)  = self . metrics_server_port  { 
392-                 result. insert ( 
393-                     "metrics_server_port" . to_string ( ) , 
394-                     Value :: new ( Some ( & namespace) ,  ValueKind :: from ( metrics_server_port) ) , 
395-                 ) ; 
396-             } 
397-             if  let  Some ( master_aggregator_endpoint)  = self . master_aggregator_endpoint . clone ( )  { 
398-                 result. insert ( 
399-                     "master_aggregator_endpoint" . to_string ( ) , 
400-                     Value :: new ( 
401-                         Some ( & namespace) , 
402-                         ValueKind :: from ( Some ( master_aggregator_endpoint) ) , 
403-                     ) , 
404-                 ) ; 
405-             } 
406- 
407-             Ok ( result) 
408-         } 
409-     } 
410- 
411-     #[ test]  
412-     fn  test_serve_command_collect ( )  { 
413-         let  serve_command = ServeCommand  { 
414-             server_ip :  Some ( "value_server_ip" . to_string ( ) ) , 
415-             server_port :  Some ( 8000 ) , 
416-             snapshot_directory :  Some ( PathBuf :: from ( "/mithril/aggregator/" ) ) , 
417-             disable_digests_cache :  true , 
418-             reset_digests_cache :  true , 
419-             allow_unparsable_block :  true , 
420-             enable_metrics_server :  true , 
421-             metrics_server_ip :  Some ( "value_metrics_server_ip" . to_string ( ) ) , 
422-             metrics_server_port :  Some ( 8080 ) , 
423-             master_aggregator_endpoint :  Some ( "value_master_aggregator_endpoint" . to_string ( ) ) , 
424-         } ; 
425- 
426-         let  result = serve_command. collect ( ) . unwrap ( ) . clone ( ) ; 
427-         let  mut  expected = HashMap :: new ( ) ; 
428-         expected. insert ( 
429-             "server_ip" . to_string ( ) , 
430-             Value :: new ( 
431-                 Some ( & "clap arguments" . to_string ( ) ) , 
432-                 ValueKind :: from ( "value_server_ip" ) , 
433-             ) , 
434-         ) ; 
435-         expected. insert ( 
436-             "server_port" . to_string ( ) , 
437-             Value :: new ( 
438-                 Some ( & "clap arguments" . to_string ( ) ) , 
439-                 ValueKind :: from ( 8000_u64 ) , 
440-             ) , 
441-         ) ; 
442-         expected. insert ( 
443-             "snapshot_directory" . to_string ( ) , 
444-             Value :: new ( 
445-                 Some ( & "clap arguments" . to_string ( ) ) , 
446-                 ValueKind :: from ( "/mithril/aggregator/" ) , 
447-             ) , 
448-         ) ; 
449-         expected. insert ( 
450-             "disable_digests_cache" . to_string ( ) , 
451-             Value :: new ( Some ( & "clap arguments" . to_string ( ) ) ,  ValueKind :: from ( true ) ) , 
452-         ) ; 
453-         expected. insert ( 
454-             "reset_digests_cache" . to_string ( ) , 
455-             Value :: new ( Some ( & "clap arguments" . to_string ( ) ) ,  ValueKind :: from ( true ) ) , 
456-         ) ; 
457-         expected. insert ( 
458-             "allow_unparsable_block" . to_string ( ) , 
459-             Value :: new ( Some ( & "clap arguments" . to_string ( ) ) ,  ValueKind :: from ( true ) ) , 
460-         ) ; 
461-         expected. insert ( 
462-             "enable_metrics_server" . to_string ( ) , 
463-             Value :: new ( Some ( & "clap arguments" . to_string ( ) ) ,  ValueKind :: from ( true ) ) , 
464-         ) ; 
465-         expected. insert ( 
466-             "metrics_server_ip" . to_string ( ) , 
467-             Value :: new ( 
468-                 Some ( & "clap arguments" . to_string ( ) ) , 
469-                 ValueKind :: from ( "value_metrics_server_ip" ) , 
470-             ) , 
471-         ) ; 
472-         expected. insert ( 
473-             "metrics_server_port" . to_string ( ) , 
474-             Value :: new ( 
475-                 Some ( & "clap arguments" . to_string ( ) ) , 
476-                 ValueKind :: from ( Some ( 8080_u64 ) ) , 
477-             ) , 
478-         ) ; 
479-         expected. insert ( 
480-             "master_aggregator_endpoint" . to_string ( ) , 
481-             Value :: new ( 
482-                 Some ( & "clap arguments" . to_string ( ) ) , 
483-                 ValueKind :: from ( "value_master_aggregator_endpoint" ) , 
484-             ) , 
485-         ) ; 
486- 
487-         assert_eq ! ( expected,  result) ; 
488- 
489-         assert_eq ! ( serve_command. collect_legacy( ) . unwrap( ) ,  result) ; 
490-     } 
491- 
492-     #[ test]  
493-     fn  test_serve_command_collect_when_empty_values ( )  { 
494-         let  serve_command = ServeCommand  { 
495-             server_ip :  None , 
496-             server_port :  None , 
497-             snapshot_directory :  None , 
498-             disable_digests_cache :  false , 
499-             reset_digests_cache :  false , 
500-             allow_unparsable_block :  false , 
501-             enable_metrics_server :  false , 
502-             metrics_server_ip :  None , 
503-             metrics_server_port :  None , 
504-             master_aggregator_endpoint :  None , 
505-         } ; 
506- 
507-         let  result = serve_command. collect ( ) . unwrap ( ) . clone ( ) ; 
508-         let  expected = HashMap :: new ( ) ; 
509- 
510-         assert_eq ! ( expected,  result) ; 
511- 
512-         assert_eq ! ( serve_command. collect_legacy( ) . unwrap( ) ,  result) ; 
513-     } 
514- } 
0 commit comments