feat(nodejs): add deleteFolderRecursive sample#4341
Conversation
This adds a sample demonstrating how to recursively delete a folder in a hierarchical namespace bucket. Fixes: b/521168740
|
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 adds a new script deleteFolderRecursive.js to recursively delete folders using the Google Cloud Storage Control client, along with a corresponding system test. The reviewer suggested improving the test by adding a file inside the folder before deleting it, ensuring that the recursive deletion behavior is properly verified.
| it('should delete a folder recursively', async () => { | ||
| const recursiveFolderName = uuid.v4(); | ||
| execSync(`node createFolder.js ${bucketName} ${recursiveFolderName}`); | ||
| const output = execSync( | ||
| `node deleteFolderRecursive.js ${bucketName} ${recursiveFolderName}` | ||
| ); |
There was a problem hiding this comment.
To properly test the recursive deletion functionality, the target folder should contain some objects (e.g., a file). If the folder is empty, the test doesn't verify that deleteFolderRecursive successfully deletes nested contents, which is its primary purpose compared to deleteFolder.
| it('should delete a folder recursively', async () => { | |
| const recursiveFolderName = uuid.v4(); | |
| execSync(`node createFolder.js ${bucketName} ${recursiveFolderName}`); | |
| const output = execSync( | |
| `node deleteFolderRecursive.js ${bucketName} ${recursiveFolderName}` | |
| ); | |
| it('should delete a folder recursively', async () => { | |
| const recursiveFolderName = uuid.v4(); | |
| execSync('node createFolder.js ' + bucketName + ' ' + recursiveFolderName); | |
| await bucket.file(recursiveFolderName + '/test.txt').save('hello'); | |
| const output = execSync( | |
| 'node deleteFolderRecursive.js ' + bucketName + ' ' + recursiveFolderName | |
| ); |
|
To use const [operation] = await controlClient.deleteFolderRecursive(request); you need to update the @google-cloud/storage-control library to its latest version. The current version in package.json (^0.5.0) does not include this method, which is why the test is failing. |
[Generated-by: AI]
|
Updated [Generated by: AI] |
This adds a sample demonstrating how to recursively delete a folder in a hierarchical namespace bucket.
Fixes: b/521168740