feat(storage): add compose file sample with deleteSourceObjects - #4359
feat(storage): add compose file sample with deleteSourceObjects#4359nidhiii-27 wants to merge 1 commit into
Conversation
Add composeFile.js sample and its corresponding tests in system-test/files.test.js. [Generated-by: AI]
There was a problem hiding this comment.
Code Review
This pull request introduces a new script storage/composeFile.js to compose multiple files in a Google Cloud Storage bucket, along with corresponding system tests in storage/system-test/files.test.js. Feedback on the changes suggests improving the robustness of command-line argument parsing by converting the boolean string to lowercase, and optimizing the test cleanup phase by deleting temporary files in parallel using Promise.all.
|
|
||
| async function composeFile() { | ||
| // If deleteSourceObjects is passed as a string from command line, parse it | ||
| const shouldDelete = String(deleteSourceObjects) === 'true'; |
There was a problem hiding this comment.
To make the command-line argument parsing more robust, consider converting the string representation of deleteSourceObjects to lowercase. This ensures that inputs like 'TRUE' or 'True' are correctly parsed as true.
| const shouldDelete = String(deleteSourceObjects) === 'true'; | |
| const shouldDelete = String(deleteSourceObjects).toLowerCase() === 'true'; |
| afterEach(async () => { | ||
| await bucket | ||
| .file(firstFile) | ||
| .delete() | ||
| .catch(() => {}); | ||
| await bucket | ||
| .file(secondFile) | ||
| .delete() | ||
| .catch(() => {}); | ||
| await bucket | ||
| .file(destinationFile) | ||
| .delete() | ||
| .catch(() => {}); | ||
| }); |
There was a problem hiding this comment.
To improve test execution speed, perform the cleanup of the source and destination files in parallel using Promise.all instead of sequentially awaiting each deletion.
afterEach(async () => {
await Promise.all([
bucket.file(firstFile).delete().catch(() => {}),
bucket.file(secondFile).delete().catch(() => {}),
bucket.file(destinationFile).delete().catch(() => {}),
]);
});
Add composeFile.js sample and its corresponding tests in system-test/files.test.js.