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

Commit

Permalink
fix: createURI() should not persist uri (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored Jun 28, 2021
1 parent d2d228e commit 5fbad65
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,11 @@ export class Upload extends Pumpify {
if (this.uri) {
this.continueUploading();
} else {
this.createURI(err => {
this.createURI((err, uri) => {
if (err) {
return this.destroy(err);
}
this.set({uri});
this.startUploading();
});
}
Expand Down Expand Up @@ -374,7 +375,6 @@ export class Upload extends Pumpify {
const resp = await this.makeRequest(reqOpts);
const uri = resp.headers.location;
this.uri = uri;
this.set({uri});
this.offset = 0;
return uri;
}
Expand Down Expand Up @@ -614,10 +614,11 @@ export class Upload extends Pumpify {
this.emit('restart');
this.numBytesWritten = 0;
this.deleteConfig();
this.createURI(err => {
this.createURI((err, uri) => {
if (err) {
return this.destroy(err);
}
this.set({uri});
this.startUploading();
});
}
Expand Down
36 changes: 27 additions & 9 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,18 @@ describe('gcs-resumable-upload', () => {
};
up.emit('writing');
});

it('should save the uri to config on first write event', done => {
const uri = 'http://newly-created-uri';
up.createURI = (callback: CreateUriCallback) => {
callback(null, uri);
};
up.set = (props: {}) => {
assert.deepStrictEqual(props, {uri});
done();
};
up.emit('writing');
});
});
});

Expand Down Expand Up @@ -403,15 +415,6 @@ describe('gcs-resumable-upload', () => {
});
});

it('should save the uri to config', done => {
up.set = (props: {}) => {
assert.deepStrictEqual(props, {uri: URI});
done();
};

up.createURI(assert.ifError);
});

it('should default the offset to 0', done => {
up.createURI((err: Error) => {
assert.ifError(err);
Expand Down Expand Up @@ -1170,6 +1173,21 @@ describe('gcs-resumable-upload', () => {
up.restart();
});

it('should save the uri to config when restarting', done => {
const uri = 'http://newly-created-uri';

up.createURI = (callback: Function) => {
callback(null, uri);
};

up.set = (props: {}) => {
assert.deepStrictEqual(props, {uri});
done();
};

up.restart();
});

it('should start uploading', done => {
up.createURI = (callback: Function) => {
up.startUploading = done;
Expand Down

0 comments on commit 5fbad65

Please sign in to comment.