@@ -1373,4 +1373,99 @@ Categories=Utility;Security;";
13731373 ) ;
13741374 }
13751375 }
1376+
1377+ #[ test]
1378+ fn status_parsing ( ) {
1379+ // Test "Up" status with details
1380+ assert_eq ! (
1381+ Status :: from_str( "Up 2 hours" ) ,
1382+ Status :: Up ( "2 hours" . to_string( ) )
1383+ ) ;
1384+ assert_eq ! (
1385+ Status :: from_str( "Up (Paused)" ) ,
1386+ Status :: Up ( "(Paused)" . to_string( ) )
1387+ ) ;
1388+
1389+ // Test "Created" status
1390+ assert_eq ! (
1391+ Status :: from_str( "Created 5 minutes ago" ) ,
1392+ Status :: Created ( "5 minutes ago" . to_string( ) )
1393+ ) ;
1394+
1395+ // Test "Exited" status
1396+ assert_eq ! (
1397+ Status :: from_str( "Exited (0) 10 seconds ago" ) ,
1398+ Status :: Exited ( "(0) 10 seconds ago" . to_string( ) )
1399+ ) ;
1400+
1401+ // Test unknown status falls back to Other
1402+ assert_eq ! (
1403+ Status :: from_str( "Unknown status" ) ,
1404+ Status :: Other ( "Unknown status" . to_string( ) )
1405+ ) ;
1406+
1407+ // Test empty string
1408+ assert_eq ! ( Status :: from_str( "" ) , Status :: Other ( "" . to_string( ) ) ) ;
1409+ }
1410+
1411+ #[ test]
1412+ fn status_display ( ) {
1413+ assert_eq ! ( Status :: Up ( "2 hours" . to_string( ) ) . to_string( ) , "Up 2 hours" ) ;
1414+ assert_eq ! (
1415+ Status :: Created ( "5 minutes ago" . to_string( ) ) . to_string( ) ,
1416+ "Created 5 minutes ago"
1417+ ) ;
1418+ assert_eq ! (
1419+ Status :: Exited ( "(0) 10 seconds ago" . to_string( ) ) . to_string( ) ,
1420+ "Exited (0) 10 seconds ago"
1421+ ) ;
1422+ assert_eq ! (
1423+ Status :: Other ( "Unknown" . to_string( ) ) . to_string( ) ,
1424+ "Unknown"
1425+ ) ;
1426+ }
1427+
1428+ #[ test]
1429+ fn volume_parsing ( ) -> Result < ( ) , Error > {
1430+ // Test single path (host only, container path same as host)
1431+ let vol = Volume :: from_str ( "/data" ) ?;
1432+ assert_eq ! ( vol. host_path, "/data" ) ;
1433+ assert_eq ! ( vol. container_path, "/data" ) ;
1434+ assert_eq ! ( vol. mode, None ) ;
1435+
1436+ // Test host:container path
1437+ let vol = Volume :: from_str ( "/host/path:/container/path" ) ?;
1438+ assert_eq ! ( vol. host_path, "/host/path" ) ;
1439+ assert_eq ! ( vol. container_path, "/container/path" ) ;
1440+ assert_eq ! ( vol. mode, None ) ;
1441+
1442+ // Test host:container:ro (read-only)
1443+ let vol = Volume :: from_str ( "/data:/data:ro" ) ?;
1444+ assert_eq ! ( vol. host_path, "/data" ) ;
1445+ assert_eq ! ( vol. container_path, "/data" ) ;
1446+ assert_eq ! ( vol. mode, Some ( VolumeMode :: ReadOnly ) ) ;
1447+
1448+ // Test invalid volume descriptor
1449+ let result = Volume :: from_str ( "/a:/b:/c:/d" ) ;
1450+ assert ! ( result. is_err( ) ) ;
1451+
1452+ Ok ( ( ) )
1453+ }
1454+
1455+ #[ test]
1456+ fn volume_display ( ) {
1457+ let vol = Volume {
1458+ host_path : "/host" . to_string ( ) ,
1459+ container_path : "/container" . to_string ( ) ,
1460+ mode : None ,
1461+ } ;
1462+ assert_eq ! ( vol. to_string( ) , "/host:/container" ) ;
1463+
1464+ let vol_ro = Volume {
1465+ host_path : "/host" . to_string ( ) ,
1466+ container_path : "/container" . to_string ( ) ,
1467+ mode : Some ( VolumeMode :: ReadOnly ) ,
1468+ } ;
1469+ assert_eq ! ( vol_ro. to_string( ) , "/host:/container:ro" ) ;
1470+ }
13761471}
0 commit comments