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

Commit

Permalink
chore(deps): use @google-cloud/projectify (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Oct 3, 2018
1 parent 9816d43 commit 8ce2ae2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"dependencies": {
"@google-cloud/common": "^0.17.0",
"@google-cloud/paginator": "^0.1.1",
"@google-cloud/projectify": "^0.3.0",
"@google-cloud/promisify": "^0.3.1",
"arrify": "^1.0.1",
"async": "^2.6.1",
Expand Down
3 changes: 2 additions & 1 deletion src/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const format = require('string-format-obj');
const is = require('is');
const util = require('util');
const {promisifyAll} = require('@google-cloud/promisify');
const {replaceProjectIdToken} = require('@google-cloud/projectify');

const Disk = require('./disk.js');

Expand Down Expand Up @@ -432,7 +433,7 @@ VM.prototype.detachDisk = function(disk, callback) {
return;
}

const diskName = common.util.replaceProjectIdToken(
const diskName = replaceProjectIdToken(
disk.formattedName,
self.zone.compute.authClient.projectId
);
Expand Down
20 changes: 14 additions & 6 deletions test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ const nodeutil = require('util');
const proxyquire = require('proxyquire');
const {ServiceObject, util} = require('@google-cloud/common');
const promisify = require('@google-cloud/promisify');

const fakeUtil = extend({}, util);
const utilCached = extend({}, util);
const {replaceProjectIdToken} = require('@google-cloud/projectify');

let promisified = false;
const fakePromisify = extend({}, promisify, {
Expand All @@ -35,6 +33,14 @@ const fakePromisify = extend({}, promisify, {
},
});

let replaceProjectIdTokenOverride;
function fakeReplaceProjectIdToken() {
return (replaceProjectIdTokenOverride || replaceProjectIdToken).apply(
null,
arguments
);
}

function FakeServiceObject() {
this.calledWith_ = arguments;
ServiceObject.apply(this, arguments);
Expand Down Expand Up @@ -72,14 +78,16 @@ describe('VM', function() {
VM = proxyquire('../src/vm.js', {
'@google-cloud/common': {
ServiceObject: FakeServiceObject,
util: fakeUtil,
},
'@google-cloud/promisify': fakePromisify,
'@google-cloud/projectify': {
replaceProjectIdToken: fakeReplaceProjectIdToken,
},
});
});

beforeEach(function() {
extend(fakeUtil, utilCached);
replaceProjectIdTokenOverride = null;
vm = new VM(ZONE, VM_NAME);
DISK = new Disk(ZONE, 'disk-name');
});
Expand Down Expand Up @@ -277,7 +285,7 @@ describe('VM', function() {
it('should replace projectId token in disk name', function(done) {
const REPLACED_DEVICE_NAME = 'replaced-device-name';

fakeUtil.replaceProjectIdToken = function(value, projectId) {
replaceProjectIdTokenOverride = function(value, projectId) {
assert.strictEqual(value, DISK.formattedName);
assert.strictEqual(projectId, COMPUTE.authClient.projectId);
return REPLACED_DEVICE_NAME;
Expand Down

0 comments on commit 8ce2ae2

Please sign in to comment.