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,