Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fix: do not override user-provided options (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Jul 9, 2020
1 parent 67ab7d7 commit e51074c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

const arrify = require('arrify');
const common = require('@google-cloud/common');
const extend = require('extend');
const format = require('string-format-obj');
const is = require('is');
const {promisifyAll} = require('@google-cloud/promisify');
Expand Down Expand Up @@ -82,7 +83,13 @@ const Image = require('./image.js');
*/
class Compute extends common.Service {
constructor(options = {}) {
options.apiEndpoint = options.apiEndpoint || 'compute.googleapis.com';
options = extend(
true,
{
apiEndpoint: 'compute.googleapis.com',
},
options
);
const config = {
apiEndpoint: options.apiEndpoint,
baseUrl: `https://${options.apiEndpoint}/compute/v1`,
Expand Down
22 changes: 21 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ describe('Compute', () => {

const calledWith = compute.calledWith_[0];

const baseUrl = 'https://compute.googleapis.com/compute/v1';
const apiEndpoint = 'compute.googleapis.com';
const baseUrl = `https://${apiEndpoint}/compute/v1`;
assert.strictEqual(calledWith.apiEndpoint, apiEndpoint);
assert.strictEqual(calledWith.baseUrl, baseUrl);
assert.deepStrictEqual(calledWith.scopes, [
'https://www.googleapis.com/auth/compute',
Expand Down Expand Up @@ -242,6 +244,24 @@ describe('Compute', () => {
assert.strictEqual(compute.getZonesStream, 'getZones');
});

it('should allow overriding the API endpoint', () => {
const apiEndpoint = 'custom.endpoint.com';
const compute = new Compute({apiEndpoint});
const calledWith = compute.calledWith_[0];

assert.strictEqual(calledWith.apiEndpoint, apiEndpoint);
assert.strictEqual(
calledWith.baseUrl,
`https://${apiEndpoint}/compute/v1`
);
});

it('should localize the poll interval', () => {
const pollIntervalMs = 9;
const compute = new Compute({pollIntervalMs});
assert.strictEqual(compute.pollIntervalMs, pollIntervalMs);
});

it('should promisify all the things', () => {
assert(promisified);
});
Expand Down

0 comments on commit e51074c

Please sign in to comment.