@@ -196,6 +196,16 @@ pub struct PortMappingEntry {
196196 pub host_ip : String ,
197197}
198198
199+ /// A named Podman volume returned by the libpod inspect API.
200+ #[ derive( Debug , Clone , Default , serde:: Deserialize ) ]
201+ #[ serde( rename_all = "PascalCase" ) ]
202+ pub struct VolumeInspect {
203+ #[ serde( default ) ]
204+ pub driver : String ,
205+ #[ serde( default ) ]
206+ pub options : HashMap < String , String > ,
207+ }
208+
199209/// A Podman event from the events stream.
200210#[ derive( Debug , Clone , serde:: Deserialize ) ]
201211#[ serde( rename_all = "PascalCase" ) ]
@@ -497,21 +507,15 @@ impl PodmanClient {
497507 }
498508 }
499509
500- /// Return whether a named volume exists . Does not create the volume.
501- pub async fn volume_exists ( & self , name : & str ) -> Result < bool , PodmanApiError > {
510+ /// Inspect a named volume. Does not create the volume.
511+ pub async fn inspect_volume ( & self , name : & str ) -> Result < VolumeInspect , PodmanApiError > {
502512 validate_name ( name) ?;
503- match self
504- . request_json :: < Value > (
505- hyper:: Method :: GET ,
506- & format ! ( "/libpod/volumes/{name}/json" ) ,
507- None ,
508- )
509- . await
510- {
511- Ok ( _) => Ok ( true ) ,
512- Err ( PodmanApiError :: NotFound ( _) ) => Ok ( false ) ,
513- Err ( e) => Err ( e) ,
514- }
513+ self . request_json (
514+ hyper:: Method :: GET ,
515+ & format ! ( "/libpod/volumes/{name}/json" ) ,
516+ None ,
517+ )
518+ . await
515519 }
516520
517521 // ── Network operations ───────────────────────────────────────────────
@@ -755,6 +759,8 @@ fn url_encode(s: &str) -> String {
755759#[ cfg( test) ]
756760mod tests {
757761 use super :: * ;
762+ use crate :: test_utils:: { StubResponse , spawn_podman_stub} ;
763+ use hyper:: StatusCode ;
758764
759765 #[ test]
760766 fn url_encode_encodes_special_characters ( ) {
@@ -794,4 +800,33 @@ mod tests {
794800 let exact_name = "a" . repeat ( MAX_NAME_LEN ) ;
795801 assert ! ( validate_name( & exact_name) . is_ok( ) ) ;
796802 }
803+
804+ #[ tokio:: test]
805+ async fn inspect_volume_parses_driver_options ( ) {
806+ let ( socket_path, request_log, handle) = spawn_podman_stub (
807+ "inspect-volume" ,
808+ vec ! [ StubResponse :: new(
809+ StatusCode :: OK ,
810+ r#"{"Name":"work-bind","Driver":"local","Options":{"type":"none","o":"rw,bind","device":"/srv/work"}}"# ,
811+ ) ] ,
812+ ) ;
813+ let client = PodmanClient :: new ( socket_path. clone ( ) ) ;
814+
815+ let volume = client
816+ . inspect_volume ( "work-bind" )
817+ . await
818+ . expect ( "volume inspect should parse" ) ;
819+
820+ assert_eq ! ( volume. driver, "local" ) ;
821+ assert_eq ! ( volume. options. get( "o" ) . map( String :: as_str) , Some ( "rw,bind" ) ) ;
822+ handle. await . expect ( "stub task should finish" ) ;
823+ assert_eq ! (
824+ request_log
825+ . lock( )
826+ . expect( "request log lock should not be poisoned" )
827+ . as_slice( ) ,
828+ [ "GET /v5.0.0/libpod/volumes/work-bind/json" ]
829+ ) ;
830+ let _ = std:: fs:: remove_file ( socket_path) ;
831+ }
797832}
0 commit comments