Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/storage/azure_storage_blob/assets.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "rust",
"Tag": "rust/azure_storage_blob_f9b39b45b4",
"Tag": "rust/azure_storage_blob_fc6c153d44",
"TagPrefix": "rust/azure_storage_blob"
}
9 changes: 9 additions & 0 deletions sdk/storage/azure_storage_blob/src/clients/blob_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,13 @@ impl BlobClient {
) -> Result<Response<BlobClientGetAccountInfoResult, NoFormat>> {
self.client.get_account_info(options).await
}

/// Returns `true` if the blob exists, and returns `false` otherwise.
///
/// # Arguments
///
/// * `options` - Optional configuration for the request.
pub async fn exists(&self) -> bool {
self.get_properties(None).await.is_ok()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,13 @@ impl BlobContainerClient {
) -> Result<Response<BlobContainerClientGetAccountInfoResult, NoFormat>> {
self.client.get_account_info(options).await
}

/// Returns `true` if the container exists, and returns `false` otherwise.
///
/// # Arguments
///
/// * `options` - Optional configuration for the request.
pub async fn exists(&self) -> bool {
self.get_properties(None).await.is_ok()
}
}
5 changes: 4 additions & 1 deletion sdk/storage/azure_storage_blob/tests/blob_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ async fn test_get_blob_properties(ctx: TestContext) -> Result<(), Box<dyn Error>
let container_client = get_container_client(recording, false).await?;
let blob_client = container_client.blob_client(get_blob_name(recording));

// Invalid Container Scenario
// Container Doesn't Exist Scenario
let response = blob_client.get_properties(None).await;

// Assert
let error = response.unwrap_err().http_status();
assert_eq!(StatusCode::NotFound, error.unwrap());
assert!(!blob_client.exists().await);

container_client.create_container(None).await?;
assert!(!blob_client.exists().await);
create_test_blob(&blob_client, None, None).await?;

// No Option Scenario
Expand All @@ -49,6 +51,7 @@ async fn test_get_blob_properties(ctx: TestContext) -> Result<(), Box<dyn Error>
assert_eq!(17, content_length.unwrap());
assert!(etag.is_some());
assert!(creation_time.is_some());
assert!(blob_client.exists().await);

container_client.delete_container(None).await?;
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async fn test_get_container_properties(ctx: TestContext) -> Result<(), Box<dyn E
assert!(response.is_err());
let error = response.unwrap_err().http_status();
assert_eq!(StatusCode::NotFound, error.unwrap());
assert!(!container_client.exists().await);

// Container Exists Scenario
container_client.create_container(None).await?;
Expand All @@ -53,6 +54,7 @@ async fn test_get_container_properties(ctx: TestContext) -> Result<(), Box<dyn E
// Assert
assert_eq!(LeaseState::Available, lease_state.unwrap());
assert!(!has_immutability_policy.unwrap());
assert!(container_client.exists().await);

container_client.delete_container(None).await?;
Ok(())
Expand Down