feat(storage): add support for 'skipIfExists' option for downloadMany… · googleapis/nodejs-storage@729efb2
@@ -30,6 +30,7 @@ import {
3030TransferManager,
3131Storage,
3232DownloadResponse,
33+DownloadManyFilesOptions,
3334} from '../src/index.js';
3435import assert from 'assert';
3536import * as path from 'path';
@@ -195,6 +196,10 @@ describe('Transfer Manager', () => {
195196});
196197197198describe('downloadManyFiles', () => {
199+beforeEach(() => {
200+sandbox.stub(fs, 'existsSync').returns(true);
201+});
202+198203it('calls download for each provided file', async () => {
199204let count = 0;
200205const firstFile = new File(bucket, 'first.txt');
@@ -276,6 +281,27 @@ describe('Transfer Manager', () => {
276281await transferManager.downloadManyFiles([file], {passthroughOptions});
277282});
278283284+it('does not download files that already exist locally when skipIfExists is true', async () => {
285+const firstFile = new File(bucket, 'first.txt');
286+sandbox.stub(firstFile, 'download').callsFake(options => {
287+assert.strictEqual(
288+(options as DownloadManyFilesOptions).skipIfExists,
289+0
290+);
291+});
292+const secondFile = new File(bucket, 'second.txt');
293+sandbox.stub(secondFile, 'download').callsFake(options => {
294+assert.strictEqual(
295+(options as DownloadManyFilesOptions).skipIfExists,
296+0
297+);
298+});
299+300+const files = [firstFile, secondFile];
301+const options = {skipIfExists: true};
302+await transferManager.downloadManyFiles(files, options);
303+});
304+279305it('does not set the destination when prefix, strip prefix and passthroughOptions.destination are not provided', async () => {
280306const options = {};
281307const filename = 'first.txt';