From 0b991d59dacd7c0da291a48b4ed6aa0c4fc76b7a Mon Sep 17 00:00:00 2001 From: Jiren Patel Date: Wed, 17 Jul 2019 23:54:23 +0530 Subject: [PATCH] fix: handle a `0` generation (#247) * Fix for zero generation number #246 --- src/index.ts | 2 +- test/test.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 0994828..770fa09 100644 --- a/src/index.ts +++ b/src/index.ts @@ -205,7 +205,7 @@ export class Upload extends Pumpify { this.bucket = cfg.bucket; const cacheKeyElements = [cfg.bucket, cfg.file]; - if (cfg.generation) { + if (typeof cfg.generation === 'number') { cacheKeyElements.push(`${cfg.generation}`); } this.cacheKey = cacheKeyElements.join('/'); diff --git a/test/test.ts b/test/test.ts index 45b597e..2aefab3 100644 --- a/test/test.ts +++ b/test/test.ts @@ -124,6 +124,24 @@ describe('gcs-resumable-upload', () => { assert.strictEqual(up.cacheKey, [BUCKET, FILE, GENERATION].join('/')); }); + it('should include ZERO generation value in the cacheKey', () => { + const upWithZeroGeneration = upload({ + bucket: BUCKET, + file: FILE, + generation: 0, + metadata: METADATA, + origin: ORIGIN, + predefinedAcl: PREDEFINED_ACL, + userProject: USER_PROJECT, + authConfig: {keyFile}, + apiEndpoint: API_ENDPOINT, + }); + assert.strictEqual( + upWithZeroGeneration.cacheKey, + [BUCKET, FILE, 0].join('/') + ); + }); + it('should not include a generation in the cacheKey if it was not set', () => { const up = upload({ bucket: BUCKET,