@@ -327,6 +327,8 @@ pub(super) async fn persist_primary_switch(
327327
328328#[ cfg( test) ]
329329mod tests {
330+ use carbide_test_support:: { Check , check_values} ;
331+
330332 use super :: * ;
331333
332334 fn switch ( node_id : & str ) -> FirmwareUpgradeDeviceInfo {
@@ -401,83 +403,108 @@ mod tests {
401403 Ok ( ( ) )
402404 }
403405
404- #[ test]
405- fn fabric_manager_status_from_entry_returns_running_when_configured ( ) {
406- let entry = rms:: ScaleUpFabricServiceStatusEntry {
407- status_json :
408- r#"{"addition-info":"CONTROL_PLANE_STATE_CONFIGURED","reason":"","status":"ok"}"#
409- . to_string ( ) ,
410- error_message : String :: new ( ) ,
411- } ;
412-
413- let status = fabric_manager_status_from_entry ( "sw-1" , & entry) ;
414-
415- assert_eq ! ( status. fabric_manager_state, FabricManagerState :: Ok ) ;
416- assert_eq ! (
417- status. addition_info. as_deref( ) ,
418- Some ( "CONTROL_PLANE_STATE_CONFIGURED" )
419- ) ;
420- assert_eq ! ( status. reason. as_deref( ) , Some ( "" ) ) ;
421- assert_eq ! ( status. display_status( ) , "running" ) ;
406+ fn entry ( status_json : & str , error_message : & str ) -> rms:: ScaleUpFabricServiceStatusEntry {
407+ rms:: ScaleUpFabricServiceStatusEntry {
408+ status_json : status_json. to_string ( ) ,
409+ error_message : error_message. to_string ( ) ,
410+ }
422411 }
423412
424- #[ test]
425- fn fabric_manager_status_from_entry_returns_not_running_for_not_ok ( ) {
426- let entry = rms:: ScaleUpFabricServiceStatusEntry {
427- status_json : r#"{"addition-info":"","reason":"stopped by user","status":"not ok"}"#
428- . to_string ( ) ,
429- error_message : String :: new ( ) ,
430- } ;
431-
432- let status = fabric_manager_status_from_entry ( "sw-1" , & entry) ;
433-
434- assert_eq ! ( status. fabric_manager_state, FabricManagerState :: NotOk ) ;
435- assert_eq ! ( status. addition_info. as_deref( ) , Some ( "" ) ) ;
436- assert_eq ! ( status. reason. as_deref( ) , Some ( "stopped by user" ) ) ;
437- assert_eq ! ( status. display_status( ) , "not_running" ) ;
413+ /// The full derived status plus its product-facing display string, so a
414+ /// table row asserts both the parsed fields and the "running"/"not_running"
415+ /// outcome the caller acts on.
416+ #[ derive( Debug , PartialEq ) ]
417+ struct Observed {
418+ status : FabricManagerStatus ,
419+ display : & ' static str ,
438420 }
439421
440- #[ test]
441- fn fabric_manager_status_from_entry_returns_not_running_for_empty_status_json ( ) {
442- let entry = rms:: ScaleUpFabricServiceStatusEntry {
443- status_json : String :: new ( ) ,
444- error_message : String :: new ( ) ,
445- } ;
446-
422+ fn observe ( entry : rms:: ScaleUpFabricServiceStatusEntry ) -> Observed {
447423 let status = fabric_manager_status_from_entry ( "sw-1" , & entry) ;
448-
449- assert_eq ! ( status. fabric_manager_state, FabricManagerState :: Unknown ) ;
450- assert_eq ! ( status. display_status( ) , "not_running" ) ;
424+ let display = status. display_status ( ) ;
425+ Observed { status, display }
451426 }
452427
453428 #[ test]
454- fn fabric_manager_status_from_entry_returns_not_running_for_error_message ( ) {
455- let entry = rms:: ScaleUpFabricServiceStatusEntry {
456- status_json : r#"{"addition-info":"CONTROL_PLANE_STATE_CONFIGURED","status":"ok"}"#
457- . to_string ( ) ,
458- error_message : "nmx-controller not started" . to_string ( ) ,
459- } ;
460-
461- let status = fabric_manager_status_from_entry ( "sw-1" , & entry) ;
462-
463- assert_eq ! ( status. fabric_manager_state, FabricManagerState :: Unknown ) ;
464- assert_eq ! (
465- status. error_message. as_deref( ) ,
466- Some ( "nmx-controller not started" )
429+ fn test_fabric_manager_status_from_entry ( ) {
430+ check_values (
431+ [
432+ Check {
433+ scenario : "ok with control-plane configured -> running" ,
434+ input : entry (
435+ r#"{"addition-info":"CONTROL_PLANE_STATE_CONFIGURED","reason":"","status":"ok"}"# ,
436+ "" ,
437+ ) ,
438+ expect : Observed {
439+ status : FabricManagerStatus {
440+ fabric_manager_state : FabricManagerState :: Ok ,
441+ addition_info : Some ( "CONTROL_PLANE_STATE_CONFIGURED" . to_string ( ) ) ,
442+ reason : Some ( String :: new ( ) ) ,
443+ error_message : None ,
444+ } ,
445+ display : "running" ,
446+ } ,
447+ } ,
448+ Check {
449+ scenario : "not ok -> not_running" ,
450+ input : entry (
451+ r#"{"addition-info":"","reason":"stopped by user","status":"not ok"}"# ,
452+ "" ,
453+ ) ,
454+ expect : Observed {
455+ status : FabricManagerStatus {
456+ fabric_manager_state : FabricManagerState :: NotOk ,
457+ addition_info : Some ( String :: new ( ) ) ,
458+ reason : Some ( "stopped by user" . to_string ( ) ) ,
459+ error_message : None ,
460+ } ,
461+ display : "not_running" ,
462+ } ,
463+ } ,
464+ Check {
465+ scenario : "empty status json -> unknown, not_running" ,
466+ input : entry ( "" , "" ) ,
467+ expect : Observed {
468+ status : FabricManagerStatus {
469+ fabric_manager_state : FabricManagerState :: Unknown ,
470+ addition_info : None ,
471+ reason : None ,
472+ error_message : None ,
473+ } ,
474+ display : "not_running" ,
475+ } ,
476+ } ,
477+ Check {
478+ scenario : "error message surfaces -> unknown, not_running" ,
479+ input : entry (
480+ r#"{"addition-info":"CONTROL_PLANE_STATE_CONFIGURED","status":"ok"}"# ,
481+ "nmx-controller not started" ,
482+ ) ,
483+ expect : Observed {
484+ status : FabricManagerStatus {
485+ fabric_manager_state : FabricManagerState :: Unknown ,
486+ addition_info : None ,
487+ reason : None ,
488+ error_message : Some ( "nmx-controller not started" . to_string ( ) ) ,
489+ } ,
490+ display : "not_running" ,
491+ } ,
492+ } ,
493+ Check {
494+ scenario : "malformed json -> unknown, not_running" ,
495+ input : entry ( "{not-json" , "" ) ,
496+ expect : Observed {
497+ status : FabricManagerStatus {
498+ fabric_manager_state : FabricManagerState :: Unknown ,
499+ addition_info : None ,
500+ reason : None ,
501+ error_message : None ,
502+ } ,
503+ display : "not_running" ,
504+ } ,
505+ } ,
506+ ] ,
507+ observe,
467508 ) ;
468- assert_eq ! ( status. display_status( ) , "not_running" ) ;
469- }
470-
471- #[ test]
472- fn fabric_manager_status_from_entry_returns_not_running_for_malformed_json ( ) {
473- let entry = rms:: ScaleUpFabricServiceStatusEntry {
474- status_json : "{not-json" . to_string ( ) ,
475- error_message : String :: new ( ) ,
476- } ;
477-
478- let status = fabric_manager_status_from_entry ( "sw-1" , & entry) ;
479-
480- assert_eq ! ( status. fabric_manager_state, FabricManagerState :: Unknown ) ;
481- assert_eq ! ( status. display_status( ) , "not_running" ) ;
482509 }
483510}
0 commit comments