Skip to content

Commit

Permalink
fix: do not modify constructor options (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
AVaksman authored and stephenplusplus committed Jan 7, 2020
1 parent 388e32d commit 4969148
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,14 @@ export class Storage extends Service {
* @param {StorageOptions} [options] Configuration options.
*/
constructor(options: StorageOptions = {}) {
options.apiEndpoint = options.apiEndpoint || 'storage.googleapis.com';
options = Object.assign({}, options, {
apiEndpoint: options.apiEndpoint || 'storage.googleapis.com',
});
const url =
process.env.STORAGE_EMULATOR_HOST ||
`https://${options.apiEndpoint}/storage/v1`;
const config = {
apiEndpoint: options.apiEndpoint,
apiEndpoint: options.apiEndpoint!,
baseUrl: url,
projectIdRequired: false,
scopes: [
Expand Down
14 changes: 14 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ describe('Storage', () => {
);
});

it('should not modify options argument', () => {
const options = {
projectId: PROJECT_ID,
};
const expectedCalledWith = Object.assign({}, options, {
apiEndpoint: 'storage.googleapis.com',
});
storage = new Storage(options);
const calledWith = storage.calledWith_[1];
assert.notStrictEqual(calledWith, options);
assert.notDeepStrictEqual(calledWith, options);
assert.deepStrictEqual(calledWith, expectedCalledWith);
});

it('should propagate the apiEndpoint option', () => {
const apiEndpoint = 'some.fake.endpoint';
storage = new Storage({
Expand Down

0 comments on commit 4969148

Please sign in to comment.