Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
fix: handle a 0 generation (#247)
Browse files Browse the repository at this point in the history
* Fix for zero generation number #246
  • Loading branch information
jiren authored and stephenplusplus committed Jul 17, 2019
1 parent 450b9ea commit 0b991d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down
18 changes: 18 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0b991d5

Please sign in to comment.