samples(storagecontrol): add delete folder recursive sample#15658
samples(storagecontrol): add delete folder recursive sample#15658nidhiii-27 wants to merge 1 commit into
Conversation
[Generated-by: AI]
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new sample and corresponding test for recursively deleting folders using the StorageControlClient. The review feedback suggests improving the sample by using the strongly-typed FolderName class instead of manual string formatting, and enhancing the test assertions to verify the exception message in addition to the status code.
| // Format: projects/{project}/buckets/{bucket}/folders/{folder} | ||
| string folderResourceName = $"projects/_/buckets/{bucketName}/folders/{folderName}"; | ||
|
|
||
| storageControlClient.DeleteFolderRecursive(folderResourceName).PollUntilCompleted(); |
There was a problem hiding this comment.
To align with the project's use of strongly-typed resource names (like BucketName), consider using FolderName instead of manually formatting the resource name string. This reduces the risk of formatting errors and makes the code cleaner.
FolderName folderResourceName = FolderName.FromProjectBucketFolder("_", bucketName, folderName);
storageControlClient.DeleteFolderRecursive(folderResourceName).PollUntilCompleted();| var ex = Assert.Throws<Grpc.Core.RpcException>(() => | ||
| storageControlClient.GetFolder(new GetFolderRequest { Name = folder.Name })); | ||
| Assert.Equal(Grpc.Core.StatusCode.NotFound, ex.StatusCode); |
There was a problem hiding this comment.
According to the repository's general rules, when asserting that an exception is thrown in a test, we should also assert on the exception message to ensure the correct exception is being propagated.
var ex = Assert.Throws<Grpc.Core.RpcException>(() =>
storageControlClient.GetFolder(new GetFolderRequest { Name = folder.Name }));
Assert.Equal(Grpc.Core.StatusCode.NotFound, ex.StatusCode);
Assert.Contains("not found", ex.Message, StringComparison.OrdinalIgnoreCase);References
- When asserting that an exception is thrown in a test, also assert on the exception message to ensure the correct exception is being propagated.
|
Pull request diff results Comparing with previous NuGet package Finished comparisons for Google.Cloud.Storage.Control.V2 |
amanda-tarafa
left a comment
There was a problem hiding this comment.
The project where you have added these samples contains generated code only. It will be deleted and re-generated the next time the API changes.
Handwritten simples go in https://github.com/GoogleCloudPlatform/dotnet-docs-samples.
|
I will be closing this PR now, because it cannot be merged on this repo. Thanks. |
This PR adds the SDK sample and tests for the hierarchical namespace recursive delete feature, resolving b/521168740.