@@ -61,3 +61,62 @@ async fn put_append_blob() {
6161 assert_eq ! ( resp. metadata. get( "second" ) , Some ( Bytes :: from( "something" ) ) ) ;
6262 assert_eq ! ( resp. metadata. get( "not_found" ) , None ) ;
6363}
64+
65+ #[ tokio:: test]
66+ async fn put_append_blob_if_match ( ) {
67+ let account =
68+ std:: env:: var ( "STORAGE_ACCOUNT" ) . expect ( "Set env variable STORAGE_ACCOUNT first!" ) ;
69+ let access_key =
70+ std:: env:: var ( "STORAGE_ACCESS_KEY" ) . expect ( "Set env variable STORAGE_ACCESS_KEY first!" ) ;
71+
72+ let blob_name: & ' static str = "create_once.txt" ;
73+ let container_name: & ' static str = "rust-if-match" ;
74+
75+ let storage_credentials = StorageCredentials :: access_key ( account. clone ( ) , access_key) ;
76+ let blob_service = BlobServiceClient :: new ( account, storage_credentials) ;
77+ let container = blob_service. container_client ( container_name) ;
78+ let blob = container. blob_client ( blob_name) ;
79+
80+ if !blob_service
81+ . list_containers ( )
82+ . into_stream ( )
83+ . next ( )
84+ . await
85+ . unwrap ( )
86+ . unwrap ( )
87+ . containers
88+ . iter ( )
89+ . any ( |x| x. name == container_name)
90+ {
91+ container
92+ . create ( )
93+ . public_access ( PublicAccess :: None )
94+ . await
95+ . unwrap ( ) ;
96+ }
97+
98+ let _ = blob. delete ( ) . await ;
99+
100+ blob. put_append_blob ( )
101+ . content_type ( "text/plain" )
102+ . if_match ( IfMatchCondition :: NotMatch ( "*" . into ( ) ) )
103+ . await
104+ . unwrap ( ) ;
105+
106+ trace ! ( "created {:?}" , blob_name) ;
107+
108+ let result = blob
109+ . put_append_blob ( )
110+ . content_type ( "text/plain" )
111+ . if_match ( IfMatchCondition :: NotMatch ( "*" . into ( ) ) )
112+ . await
113+ . unwrap_err ( ) ;
114+
115+ assert_eq ! (
116+ result. kind( ) ,
117+ & azure_core:: error:: ErrorKind :: HttpResponse {
118+ status: azure_core:: StatusCode :: Conflict ,
119+ error_code: Some ( "BlobAlreadyExists" . into( ) )
120+ }
121+ ) ;
122+ }
0 commit comments