Skip to content

feat(nodejs): add deleteFolderRecursive sample#4341

Draft
nidhiii-27 wants to merge 2 commits into
mainfrom
feat-deleteFolderRecursive
Draft

feat(nodejs): add deleteFolderRecursive sample#4341
nidhiii-27 wants to merge 2 commits into
mainfrom
feat-deleteFolderRecursive

Conversation

@nidhiii-27

Copy link
Copy Markdown
Contributor

This adds a sample demonstrating how to recursively delete a folder in a hierarchical namespace bucket.

Fixes: b/521168740

This adds a sample demonstrating how to recursively delete a folder in a hierarchical namespace bucket.

Fixes: b/521168740
@nidhiii-27 nidhiii-27 requested review from a team as code owners June 11, 2026 10:56
@snippet-bot

snippet-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Jun 11, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +80 to +85
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}`
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nidhiii-27 nidhiii-27 marked this pull request as draft June 11, 2026 11:00
@nidhiii-27

Copy link
Copy Markdown
Contributor Author

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.

@nidhiii-27 nidhiii-27 added ai-generated Generated by AI storage-sample-architect Generated by storage-sample-architect skill labels Jun 11, 2026
@nidhiii-27

nidhiii-27 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Updated @google-cloud/storage-control dependency to the latest version (^0.10.0) in storage-control/package.json to resolve the test failure.

[Generated by: AI]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Generated by AI samples Issues that are directly related to samples. storage-sample-architect Generated by storage-sample-architect skill

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant