Skip to content

Commit e1896c7

Browse files
[Storage] set_legal_hold for BlobClient (#3335)
1 parent 54ef1e9 commit e1896c7

File tree

13 files changed

+198
-269
lines changed

13 files changed

+198
-269
lines changed

sdk/core/azure_core_test_macros/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ use proc_macro::TokenStream;
99

1010
/// Attribute client library tests to play back recordings, record sessions, or execute tests without recording.
1111
///
12+
/// # Arguments
13+
///
14+
/// * `live` - Run the test only in live mode. The test will be ignored unless `AZURE_TEST_MODE=live`.
15+
/// * `playback` - Run the test only in playback mode. The test will be ignored unless `AZURE_TEST_MODE=playback`.
16+
/// Note: Only use this for tests that validate playback-specific behavior. Most tests should not use this option.
17+
///
1218
/// # Examples
1319
///
14-
/// For live or recorded tests, you must declare an async function that accepts a `TestContext` and returns a `Result<T, E>`.
20+
/// For live or recorded tests (the default), you must declare an async function that accepts a `TestContext` and returns a `Result<T, E>`.
1521
///
1622
/// ```
1723
/// use azure_core::Result;

sdk/core/azure_core_test_macros/src/test.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use syn::{
1010
};
1111

1212
const INVALID_RECORDED_ATTRIBUTE_MESSAGE: &str =
13-
"expected `#[recorded::test]` or `#[recorded::test(live)]`";
13+
"expected `#[recorded::test]`, `#[recorded::test(live)]`, or `#[recorded::test(playback)]`";
1414
const INVALID_RECORDED_FUNCTION_MESSAGE: &str =
1515
"expected `async fn(TestContext)` function signature with `Result<T, E>` return";
1616

@@ -50,6 +50,13 @@ pub fn parse_test(attr: TokenStream, item: TokenStream) -> Result<TokenStream> {
5050
});
5151
}
5252

53+
// Ignore playback-only tests if not running playback tests.
54+
if recorded_attrs.playback && test_mode != TestMode::Playback {
55+
test_attr.extend(quote! {
56+
#[ignore = "skipping playback-only tests"]
57+
});
58+
}
59+
5360
let fn_name = &original_sig.ident;
5461
let mut inputs = original_sig.inputs.iter();
5562
let setup = match inputs.next() {
@@ -110,6 +117,7 @@ static TEST_MODE: LazyLock<TestMode> = LazyLock::new(|| {
110117
#[derive(Debug, Default)]
111118
struct Attributes {
112119
live: bool,
120+
playback: bool,
113121
}
114122

115123
impl Parse for Attributes {
@@ -123,6 +131,7 @@ impl Parse for Attributes {
123131
})?;
124132
match ident.to_string().as_str() {
125133
"live" => attrs.live = true,
134+
"playback" => attrs.playback = true,
126135
_ => {
127136
return Err(syn::Error::new(
128137
arg.span(),
@@ -139,7 +148,6 @@ impl Parse for Attributes {
139148
}
140149
}
141150
}
142-
143151
Ok(attrs)
144152
}
145153
}
@@ -274,4 +282,33 @@ mod tests {
274282
};
275283
parse_test(attr, item).unwrap();
276284
}
285+
286+
#[test]
287+
fn attributes_parse_playback() {
288+
let attr: Attribute = syn::parse_quote! {
289+
#[recorded(playback)]
290+
};
291+
let attrs: Attributes = attr.parse_args().unwrap();
292+
assert!(attrs.playback);
293+
assert!(!attrs.live);
294+
}
295+
296+
#[test]
297+
fn attributes_parse_conflicting() {
298+
let attr: Attribute = syn::parse_quote! {
299+
#[recorded(live, playback)]
300+
};
301+
attr.parse_args::<Attributes>().unwrap_err();
302+
}
303+
304+
#[test]
305+
fn parse_recorded_playback_only() {
306+
let attr = quote! { playback };
307+
let item = quote! {
308+
async fn playback_only(ctx: TestContext) -> azure_core::Result<()> {
309+
todo!()
310+
}
311+
};
312+
parse_test(attr, item).unwrap();
313+
}
277314
}

sdk/storage/azure_storage_blob/CHANGELOG.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features Added
66

7+
- Added support for `set_legal_hold` to `BlobClient`.
78
- Added `continuation_token` to `PagerOptions` for methods that return a `Pager`.
89

910
### Breaking Changes
@@ -39,10 +40,6 @@
3940
- The `credential` parameter is now `Optional` on `new()` client constructors, allowing for construction of public access clients.
4041
- Renamed `Response<T, F>::into_body(self) -> Result<Response<T>>` to `into_model(self) -> Result<Response<T>>`. `into_body(self)` now returns a `ResponseBody`.
4142

42-
### Bugs Fixed
43-
44-
### Other Changes
45-
4643
## 0.6.0 (2025-10-06)
4744

4845
### Features Added
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "rust",
4-
"Tag": "rust/azure_storage_blob_1e5e3b2c6c",
4+
"Tag": "rust/azure_storage_blob_ceab74b7c5",
55
"TagPrefix": "rust/azure_storage_blob"
66
}

sdk/storage/azure_storage_blob/src/clients/blob_client.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use crate::{
1515
AccessTier, BlobClientAcquireLeaseOptions, BlobClientBreakLeaseOptions,
1616
BlobClientChangeLeaseOptions, BlobClientDeleteOptions, BlobClientDownloadOptions,
1717
BlobClientGetAccountInfoOptions, BlobClientGetPropertiesOptions, BlobClientGetTagsOptions,
18-
BlobClientReleaseLeaseOptions, BlobClientRenewLeaseOptions, BlobClientSetMetadataOptions,
19-
BlobClientSetPropertiesOptions, BlobClientSetTagsOptions, BlobClientSetTierOptions,
20-
BlobTags, BlockBlobClientUploadOptions, StorageErrorCode,
18+
BlobClientReleaseLeaseOptions, BlobClientRenewLeaseOptions, BlobClientSetLegalHoldOptions,
19+
BlobClientSetMetadataOptions, BlobClientSetPropertiesOptions, BlobClientSetTagsOptions,
20+
BlobClientSetTierOptions, BlobTags, BlockBlobClientUploadOptions, StorageErrorCode,
2121
},
2222
pipeline::StorageHeadersPolicy,
2323
AppendBlobClient, BlobClientOptions, BlockBlobClient, PageBlobClient,
@@ -436,4 +436,18 @@ impl BlobClient {
436436
Err(e) => Err(e),
437437
}
438438
}
439+
440+
/// Sets a legal hold on the blob.
441+
///
442+
/// # Arguments
443+
///
444+
/// * `legal_hold` - Specifies the legal hold status to set on the blob.
445+
/// * `options` - Optional configuration for the request.
446+
pub async fn set_legal_hold(
447+
&self,
448+
legal_hold: bool,
449+
options: Option<BlobClientSetLegalHoldOptions<'_>>,
450+
) -> Result<Response<(), NoFormat>> {
451+
self.client.set_legal_hold(legal_hold, options).await
452+
}
439453
}

sdk/storage/azure_storage_blob/src/generated/clients/blob_client.rs

Lines changed: 5 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/azure_storage_blob/src/generated/clients/blob_container_client.rs

Lines changed: 15 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)