diff --git a/packages/google-cloud-compute/package.json b/packages/google-cloud-compute/package.json index 0b726c4eaa4..813c4ea4d3f 100644 --- a/packages/google-cloud-compute/package.json +++ b/packages/google-cloud-compute/package.json @@ -61,8 +61,8 @@ "string-format-obj": "^1.0.0" }, "devDependencies": { - "mocha": "^2.1.0", "concat-stream": "^1.5.0", + "mocha": "^3.0.1", "propprop": "^0.3.0", "proxyquire": "^1.7.10" }, @@ -75,4 +75,4 @@ "engines": { "node": ">=0.12.0" } -} \ No newline at end of file +} diff --git a/packages/google-cloud-compute/src/address.js b/packages/google-cloud-compute/src/address.js index 8c3e634bcf5..db08b38288e 100644 --- a/packages/google-cloud-compute/src/address.js +++ b/packages/google-cloud-compute/src/address.js @@ -21,19 +21,7 @@ 'use strict'; var common = require('@google-cloud/common'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; +var util = require('util'); /*! Developer Documentation * @@ -129,7 +117,7 @@ function Address(region, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: region, baseUrl: '/addresses', id: name, @@ -141,7 +129,7 @@ function Address(region, name) { this.region = region; } -nodeutil.inherits(Address, ServiceObject); +util.inherits(Address, common.ServiceObject); /** * Delete the address. @@ -161,7 +149,7 @@ nodeutil.inherits(Address, ServiceObject); * }); */ Address.prototype.delete = function(callback) { - callback = callback || util.noop; + callback = callback || common.util.noop; var region = this.region; diff --git a/packages/google-cloud-compute/src/autoscaler.js b/packages/google-cloud-compute/src/autoscaler.js index c7f3bfef224..89032bdb817 100644 --- a/packages/google-cloud-compute/src/autoscaler.js +++ b/packages/google-cloud-compute/src/autoscaler.js @@ -21,19 +21,7 @@ 'use strict'; var common = require('@google-cloud/common'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; +var util = require('util'); /*! Developer Documentation * @@ -135,7 +123,7 @@ function Autoscaler(zone, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: zone, baseUrl: '/autoscalers', id: name, @@ -147,7 +135,7 @@ function Autoscaler(zone, name) { this.zone = zone; } -nodeutil.inherits(Autoscaler, ServiceObject); +util.inherits(Autoscaler, common.ServiceObject); /** * Delete the autoscaler. @@ -167,11 +155,11 @@ nodeutil.inherits(Autoscaler, ServiceObject); * }); */ Autoscaler.prototype.delete = function(callback) { - callback = callback || util.noop; + callback = callback || common.util.noop; var zone = this.zone; - ServiceObject.prototype.delete.call(this, function(err, resp) { + common.ServiceObject.prototype.delete.call(this, function(err, resp) { if (err) { callback(err, null, resp); return; @@ -210,7 +198,7 @@ Autoscaler.prototype.delete = function(callback) { Autoscaler.prototype.setMetadata = function(metadata, callback) { var zone = this.zone; - callback = callback || util.noop; + callback = callback || common.util.noop; metadata = metadata || {}; metadata.name = this.name; diff --git a/packages/google-cloud-compute/src/disk.js b/packages/google-cloud-compute/src/disk.js index fc801c87933..5400ee87033 100644 --- a/packages/google-cloud-compute/src/disk.js +++ b/packages/google-cloud-compute/src/disk.js @@ -24,13 +24,7 @@ var common = require('@google-cloud/common'); var extend = require('extend'); var format = require('string-format-obj'); var is = require('is'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; +var util = require('util'); /** * @type {module:compute/snapshot} @@ -38,12 +32,6 @@ var ServiceObject = common.ServiceObject; */ var Snapshot = require('./snapshot.js'); -/** - * @type {module:common/util} - * @private - */ -var util = common.util; - /*! Developer Documentation * * @param {module:zone} zone - Zone this disk belongs to. @@ -141,7 +129,7 @@ function Disk(zone, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: zone, baseUrl: '/disks', id: name, @@ -155,7 +143,7 @@ function Disk(zone, name) { this.formattedName = Disk.formatName_(zone, name); } -nodeutil.inherits(Disk, ServiceObject); +util.inherits(Disk, common.ServiceObject); /** * Format a disk's name how the API expects. @@ -252,9 +240,9 @@ Disk.prototype.createSnapshot = function(name, options, callback) { Disk.prototype.delete = function(callback) { var zone = this.zone; - callback = callback || util.noop; + callback = callback || common.util.noop; - ServiceObject.prototype.delete.call(this, function(err, resp) { + common.ServiceObject.prototype.delete.call(this, function(err, resp) { if (err) { callback(err, null, resp); return; diff --git a/packages/google-cloud-compute/src/firewall.js b/packages/google-cloud-compute/src/firewall.js index 4cfd156dc74..c95dc1d2621 100644 --- a/packages/google-cloud-compute/src/firewall.js +++ b/packages/google-cloud-compute/src/firewall.js @@ -21,19 +21,7 @@ 'use strict'; var common = require('@google-cloud/common'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; +var util = require('util'); /*! Developer Documentation * @@ -131,7 +119,7 @@ function Firewall(compute, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: compute, baseUrl: '/global/firewalls', id: name, @@ -144,7 +132,7 @@ function Firewall(compute, name) { this.metadata.network = 'global/networks/default'; } -nodeutil.inherits(Firewall, ServiceObject); +util.inherits(Firewall, common.ServiceObject); /** * Delete the firewall. @@ -166,9 +154,9 @@ nodeutil.inherits(Firewall, ServiceObject); Firewall.prototype.delete = function(callback) { var compute = this.compute; - callback = callback || util.noop; + callback = callback || common.util.noop; - ServiceObject.prototype.delete.call(this, function(err, resp) { + common.ServiceObject.prototype.delete.call(this, function(err, resp) { if (err) { callback(err, null, resp); return; @@ -207,7 +195,7 @@ Firewall.prototype.delete = function(callback) { Firewall.prototype.setMetadata = function(metadata, callback) { var compute = this.compute; - callback = callback || util.noop; + callback = callback || common.util.noop; metadata = metadata || {}; metadata.name = this.name; diff --git a/packages/google-cloud-compute/src/health-check.js b/packages/google-cloud-compute/src/health-check.js index 91c680f5cf9..0694ac6c3c3 100644 --- a/packages/google-cloud-compute/src/health-check.js +++ b/packages/google-cloud-compute/src/health-check.js @@ -23,19 +23,7 @@ var common = require('@google-cloud/common'); var extend = require('extend'); var is = require('is'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; +var util = require('util'); /*! Developer Documentation * @@ -143,7 +131,7 @@ function HealthCheck(compute, name, options) { var https = options.https; this.compute = compute; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: compute, baseUrl: '/global/' + (https ? 'httpsHealthChecks' : 'httpHealthChecks'), id: name, @@ -161,7 +149,7 @@ function HealthCheck(compute, name, options) { }); } -nodeutil.inherits(HealthCheck, ServiceObject); +util.inherits(HealthCheck, common.ServiceObject); /** * Delete the health check. @@ -184,9 +172,9 @@ nodeutil.inherits(HealthCheck, ServiceObject); HealthCheck.prototype.delete = function(callback) { var compute = this.compute; - callback = callback || util.noop; + callback = callback || common.util.noop; - ServiceObject.prototype.delete.call(this, function(err, resp) { + common.ServiceObject.prototype.delete.call(this, function(err, resp) { if (err) { callback(err, null, resp); return; @@ -227,9 +215,11 @@ HealthCheck.prototype.delete = function(callback) { HealthCheck.prototype.setMetadata = function(metadata, callback) { var compute = this.compute; - callback = callback || util.noop; + callback = callback || common.util.noop; + + var setMetadata = common.ServiceObject.prototype.setMetadata; - ServiceObject.prototype.setMetadata.call(this, metadata, function(err, resp) { + setMetadata.call(this, metadata, function(err, resp) { if (err) { callback(err, null, resp); return; diff --git a/packages/google-cloud-compute/src/index.js b/packages/google-cloud-compute/src/index.js index cf1a52c4b53..03dc658039c 100644 --- a/packages/google-cloud-compute/src/index.js +++ b/packages/google-cloud-compute/src/index.js @@ -24,8 +24,7 @@ var arrify = require('arrify'); var common = require('@google-cloud/common'); var extend = require('extend'); var is = require('is'); -var nodeutil = require('util'); -var PKG = require('../package.json'); +var util = require('util'); /** * @type {module:compute/firewall} @@ -63,17 +62,11 @@ var Region = require('./region.js'); */ var Rule = require('./rule.js'); -/** - * @type {module:common/service} - * @private - */ -var Service = common.Service; - /** * @type {module:compute/service} * @private */ -var ServiceClass = require('./service.js'); +var Service = require('./service.js'); /** * @type {module:compute/snapshot} @@ -81,24 +74,14 @@ var ServiceClass = require('./service.js'); */ var Snapshot = require('./snapshot.js'); -/** - * @type {module:common/stream-router} - * @private - */ -var streamRouter = common.streamRouter; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; - /** * @type {module:compute/zone} * @private */ var Zone = require('./zone.js'); +var PKG = require('../package.json'); + /** * A Compute object allows you to interact with the Google Compute Engine API. * Using this object, you can access your instances with {module:compute/vm}, @@ -128,7 +111,7 @@ var Zone = require('./zone.js'); */ function Compute(options) { if (!(this instanceof Compute)) { - options = util.normalizeArguments(this, options); + options = common.util.normalizeArguments(this, options); return new Compute(options); } @@ -138,10 +121,10 @@ function Compute(options) { userAgent: PKG.name + '/' + PKG.version }; - Service.call(this, config, options); + common.Service.call(this, config, options); } -nodeutil.inherits(Compute, Service); +util.inherits(Compute, common.Service); /** * Create a firewall. @@ -2456,7 +2439,7 @@ Compute.prototype.rule = function(name) { * var service = gce.service('service-name'); */ Compute.prototype.service = function(name) { - return new ServiceClass(this, name); + return new Service(this, name); }; /** @@ -2494,7 +2477,7 @@ Compute.prototype.zone = function(name) { * These methods can be used with either a callback or as a readable object * stream. `streamRouter` is used to add this dual behavior. */ -streamRouter.extend(Compute, [ +common.streamRouter.extend(Compute, [ 'getAddresses', 'getAutoscalers', 'getDisks', @@ -2519,7 +2502,7 @@ Compute.Network = Network; Compute.Operation = Operation; Compute.Region = Region; Compute.Rule = Rule; -Compute.ServiceClass = ServiceClass; +Compute.Service = Service; Compute.Snapshot = Snapshot; Compute.Zone = Zone; diff --git a/packages/google-cloud-compute/src/instance-group.js b/packages/google-cloud-compute/src/instance-group.js index 9c33acc8e41..f38388b35e3 100644 --- a/packages/google-cloud-compute/src/instance-group.js +++ b/packages/google-cloud-compute/src/instance-group.js @@ -24,25 +24,7 @@ var arrify = require('arrify'); var common = require('@google-cloud/common'); var extend = require('extend'); var is = require('is'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/stream-router} - * @private - */ -var streamRouter = common.streamRouter; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; +var util = require('util'); /*! Developer Documentation * @@ -142,7 +124,7 @@ function InstanceGroup(zone, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: zone, baseUrl: '/instanceGroups', id: name, @@ -154,7 +136,7 @@ function InstanceGroup(zone, name) { this.name = name; } -nodeutil.inherits(InstanceGroup, ServiceObject); +util.inherits(InstanceGroup, common.ServiceObject); /** * Format a map of named ports in the way the API expects. @@ -244,9 +226,9 @@ InstanceGroup.prototype.add = function(vms, callback) { InstanceGroup.prototype.delete = function(callback) { var self = this; - callback = callback || util.noop; + callback = callback || common.util.noop; - ServiceObject.prototype.delete.call(this, function(err, resp) { + common.ServiceObject.prototype.delete.call(this, function(err, resp) { if (err) { callback(err, null, resp); return; @@ -452,7 +434,7 @@ InstanceGroup.prototype.remove = function(vms, callback) { InstanceGroup.prototype.setPorts = function(ports, callback) { var self = this; - callback = callback || util.noop; + callback = callback || common.util.noop; this.request({ method: 'POST', @@ -478,6 +460,6 @@ InstanceGroup.prototype.setPorts = function(ports, callback) { * These methods can be used with either a callback or as a readable object * stream. `streamRouter` is used to add this dual behavior. */ -streamRouter.extend(InstanceGroup, ['getVMs']); +common.streamRouter.extend(InstanceGroup, ['getVMs']); module.exports = InstanceGroup; diff --git a/packages/google-cloud-compute/src/machine-type.js b/packages/google-cloud-compute/src/machine-type.js index 7fa3a814dec..6ea9fc05c75 100644 --- a/packages/google-cloud-compute/src/machine-type.js +++ b/packages/google-cloud-compute/src/machine-type.js @@ -21,13 +21,7 @@ 'use strict'; var common = require('@google-cloud/common'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; +var util = require('util'); /*! Developer Documentation * @@ -100,7 +94,7 @@ function MachineType(zone, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: zone, baseUrl: '/machineTypes', id: name, @@ -111,6 +105,6 @@ function MachineType(zone, name) { this.name = name; } -nodeutil.inherits(MachineType, ServiceObject); +util.inherits(MachineType, common.ServiceObject); module.exports = MachineType; diff --git a/packages/google-cloud-compute/src/network.js b/packages/google-cloud-compute/src/network.js index 007546d309a..3c516764a2b 100644 --- a/packages/google-cloud-compute/src/network.js +++ b/packages/google-cloud-compute/src/network.js @@ -24,19 +24,7 @@ var common = require('@google-cloud/common'); var extend = require('extend'); var format = require('string-format-obj'); var is = require('is'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; +var util = require('util'); /*! Developer Documentation * @@ -133,7 +121,7 @@ function Network(compute, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: compute, baseUrl: '/global/networks', id: name, @@ -146,7 +134,7 @@ function Network(compute, name) { this.name = name; } -nodeutil.inherits(Network, ServiceObject); +util.inherits(Network, common.ServiceObject); /** * Format a network's name how the API expects. @@ -374,9 +362,9 @@ Network.prototype.getSubnetworks = function(options, callback) { Network.prototype.delete = function(callback) { var compute = this.compute; - callback = callback || util.noop; + callback = callback || common.util.noop; - ServiceObject.prototype.delete.call(this, function(err, resp) { + common.ServiceObject.prototype.delete.call(this, function(err, resp) { if (err) { callback(err, null, resp); return; diff --git a/packages/google-cloud-compute/src/operation.js b/packages/google-cloud-compute/src/operation.js index 57d721faaf5..5504927e5cf 100644 --- a/packages/google-cloud-compute/src/operation.js +++ b/packages/google-cloud-compute/src/operation.js @@ -24,18 +24,6 @@ var common = require('@google-cloud/common'); var events = require('events'); var modelo = require('modelo'); -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; - /*! Developer Documentation * * @param {module:compute} scope - The scope of the operation: a `Compute`, @@ -156,7 +144,7 @@ function Operation(scope, name) { get: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: scope, baseUrl: isCompute ? '/global/operations' : '/operations', id: name, @@ -172,7 +160,7 @@ function Operation(scope, name) { this.listenForEvents_(); } -modelo.inherits(Operation, ServiceObject, events.EventEmitter); +modelo.inherits(Operation, common.ServiceObject, events.EventEmitter); /** * Get the operation's metadata. For a detailed description of metadata see @@ -196,9 +184,11 @@ modelo.inherits(Operation, ServiceObject, events.EventEmitter); Operation.prototype.getMetadata = function(callback) { var self = this; - callback = callback || util.noop; + callback = callback || common.util.noop; + + var getMetadata = common.ServiceObject.prototype.getMetadata; - ServiceObject.prototype.getMetadata.call(this, function(err, apiResponse) { + getMetadata.call(this, function(err, apiResponse) { // An Operation entity contains a property named `error`. This makes // `request` think the operation failed, and will return an ApiError to // this callback. We have to make sure this isn't a false error by seeing if @@ -267,7 +257,7 @@ Operation.prototype.startPolling_ = function() { this.getMetadata(function(err, metadata, apiResponse) { // Parsing the response body will automatically create an ApiError object if // the operation failed. - var parsedHttpRespBody = util.parseHttpRespBody(apiResponse); + var parsedHttpRespBody = common.util.parseHttpRespBody(apiResponse); err = err || parsedHttpRespBody.err; if (err) { diff --git a/packages/google-cloud-compute/src/region.js b/packages/google-cloud-compute/src/region.js index 96f82c2e7f8..2cfb960e84f 100644 --- a/packages/google-cloud-compute/src/region.js +++ b/packages/google-cloud-compute/src/region.js @@ -23,7 +23,7 @@ var common = require('@google-cloud/common'); var extend = require('extend'); var is = require('is'); -var nodeutil = require('util'); +var util = require('util'); /** * @type {module:compute/address} @@ -49,24 +49,12 @@ var Operation = require('./operation.js'); */ var Rule = require('./rule.js'); -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - /** * @type {module:compute/subnetwork} * @private */ var Subnetwork = require('./subnetwork.js'); -/** - * @type {module:common/stream-router} - * @private - */ -var streamRouter = common.streamRouter; - /*! Developer Documentation * * @param {module:compute} compute - Compute object this region belongs to. @@ -134,7 +122,7 @@ function Region(compute, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: compute, baseUrl: '/regions', id: name, @@ -153,7 +141,7 @@ function Region(compute, name) { }); } -nodeutil.inherits(Region, ServiceObject); +util.inherits(Region, common.ServiceObject); /** * Get a reference to a Google Compute Engine address in this region. @@ -823,7 +811,7 @@ Region.prototype.subnetwork = function(name) { * These methods can be used with either a callback or as a readable object * stream. `streamRouter` is used to add this dual behavior. */ -streamRouter.extend(Region, [ +common.streamRouter.extend(Region, [ 'getAddresses', 'getOperations', 'getRules', diff --git a/packages/google-cloud-compute/src/rule.js b/packages/google-cloud-compute/src/rule.js index c92a800073b..d31c099dc58 100644 --- a/packages/google-cloud-compute/src/rule.js +++ b/packages/google-cloud-compute/src/rule.js @@ -21,19 +21,7 @@ 'use strict'; var common = require('@google-cloud/common'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; +var util = require('util'); /*! Developer Documentation * @@ -152,7 +140,7 @@ function Rule(scope, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: scope, baseUrl: (isGlobalRule ? '/global' : '') + '/forwardingRules', id: name, @@ -163,7 +151,7 @@ function Rule(scope, name) { this.scope = scope; } -nodeutil.inherits(Rule, ServiceObject); +util.inherits(Rule, common.ServiceObject); /** * Delete the rule. @@ -184,11 +172,11 @@ nodeutil.inherits(Rule, ServiceObject); * }); */ Rule.prototype.delete = function(callback) { - callback = callback || util.noop; + callback = callback || common.util.noop; var scope = this.scope; - ServiceObject.prototype.delete.call(this, function(err, resp) { + common.ServiceObject.prototype.delete.call(this, function(err, resp) { if (err) { callback(err, null, resp); return; @@ -223,7 +211,7 @@ Rule.prototype.delete = function(callback) { * }); */ Rule.prototype.setTarget = function(target, callback) { - callback = callback || util.noop; + callback = callback || common.util.noop; var scope = this.scope; diff --git a/packages/google-cloud-compute/src/service.js b/packages/google-cloud-compute/src/service.js index 2d7e5525f0e..4b04ba7f42e 100644 --- a/packages/google-cloud-compute/src/service.js +++ b/packages/google-cloud-compute/src/service.js @@ -24,19 +24,7 @@ var arrify = require('arrify'); var common = require('@google-cloud/common'); var format = require('string-format-obj'); var is = require('is'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; +var util = require('util'); /*! Developer Documentation * @@ -145,7 +133,7 @@ function Service(compute, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: compute, baseUrl: '/global/backendServices', id: name, @@ -157,7 +145,7 @@ function Service(compute, name) { this.name = name; } -nodeutil.inherits(Service, ServiceObject); +util.inherits(Service, common.ServiceObject); /** * Delete the backend service. @@ -179,9 +167,9 @@ nodeutil.inherits(Service, ServiceObject); Service.prototype.delete = function(callback) { var compute = this.compute; - callback = callback || util.noop; + callback = callback || common.util.noop; - ServiceObject.prototype.delete.call(this, function(err, resp) { + common.ServiceObject.prototype.delete.call(this, function(err, resp) { if (err) { callback(err, null, resp); return; @@ -279,7 +267,7 @@ Service.prototype.getHealth = function(group, callback) { Service.prototype.setMetadata = function(metadata, callback) { var compute = this.compute; - callback = callback || util.noop; + callback = callback || common.util.noop; this.request({ method: 'PATCH', diff --git a/packages/google-cloud-compute/src/snapshot.js b/packages/google-cloud-compute/src/snapshot.js index 7ceee2fcf46..edb2be6b4b5 100644 --- a/packages/google-cloud-compute/src/snapshot.js +++ b/packages/google-cloud-compute/src/snapshot.js @@ -21,19 +21,7 @@ 'use strict'; var common = require('@google-cloud/common'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; +var util = require('util'); /*! Developer Documentation * @@ -150,13 +138,13 @@ function Snapshot(scope, name) { config.methods.create = true; } - ServiceObject.call(this, config); + common.ServiceObject.call(this, config); this.compute = isDisk ? scope.compute : scope; this.name = name; } -nodeutil.inherits(Snapshot, ServiceObject); +util.inherits(Snapshot, common.ServiceObject); /** * Delete the snapshot. @@ -176,11 +164,11 @@ nodeutil.inherits(Snapshot, ServiceObject); * }); */ Snapshot.prototype.delete = function(callback) { - callback = callback || util.noop; + callback = callback || common.util.noop; var compute = this.compute; - ServiceObject.prototype.delete.call(this, function(err, resp) { + common.ServiceObject.prototype.delete.call(this, function(err, resp) { if (err) { callback(err, null, resp); return; diff --git a/packages/google-cloud-compute/src/subnetwork.js b/packages/google-cloud-compute/src/subnetwork.js index dcd67a75400..06773bdd88b 100644 --- a/packages/google-cloud-compute/src/subnetwork.js +++ b/packages/google-cloud-compute/src/subnetwork.js @@ -21,20 +21,7 @@ 'use strict'; var common = require('@google-cloud/common'); -var nodeutil = require('util'); - -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; - +var util = require('util'); /*! Developer Documentation * @@ -139,7 +126,7 @@ function Subnetwork(region, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: region, baseUrl: '/subnetworks', id: this.name, @@ -148,7 +135,7 @@ function Subnetwork(region, name) { }); } -nodeutil.inherits(Subnetwork, ServiceObject); +util.inherits(Subnetwork, common.ServiceObject); /** * Delete the subnetwork. @@ -168,7 +155,7 @@ nodeutil.inherits(Subnetwork, ServiceObject); * }); */ Subnetwork.prototype.delete = function(callback) { - callback = callback || util.noop; + callback = callback || common.util.noop; var region = this.region; diff --git a/packages/google-cloud-compute/src/vm.js b/packages/google-cloud-compute/src/vm.js index 6ed9bf252c0..ea0ea96348c 100644 --- a/packages/google-cloud-compute/src/vm.js +++ b/packages/google-cloud-compute/src/vm.js @@ -25,7 +25,7 @@ var createErrorClass = require('create-error-class'); var extend = require('extend'); var format = require('string-format-obj'); var is = require('is'); -var nodeutil = require('util'); +var util = require('util'); /** * @type {module:compute/disk} @@ -33,18 +33,6 @@ var nodeutil = require('util'); */ var Disk = require('./disk.js'); -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/util} - * @private - */ -var util = common.util; - /** * Custom error type for errors related to detaching a disk. * @@ -165,7 +153,7 @@ function VM(zone, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: zone, baseUrl: '/instances', id: this.name, @@ -174,7 +162,7 @@ function VM(zone, name) { }); } -nodeutil.inherits(VM, ServiceObject); +util.inherits(VM, common.ServiceObject); /** * Attach a disk to the instance. @@ -267,7 +255,7 @@ VM.prototype.delete = function(callback) { this.request({ method: 'DELETE', uri: '' - }, callback || util.noop); + }, callback || common.util.noop); }; /** @@ -331,7 +319,7 @@ VM.prototype.detachDisk = function(disk, callback) { qs: { deviceName: deviceName } - }, callback || util.noop); + }, callback || common.util.noop); }); }; @@ -363,7 +351,9 @@ VM.prototype.getSerialPortOutput = function(port, callback) { } }; - ServiceObject.prototype.request.call(this, reqOpts, function(err, resp) { + var request = common.ServiceObject.prototype.request; + + request.call(this, reqOpts, function(err, resp) { if (err) { callback(err, null, resp); return; @@ -420,7 +410,7 @@ VM.prototype.reset = function(callback) { this.request({ method: 'POST', uri: '/reset' - }, callback || util.noop); + }, callback || common.util.noop); }; /** @@ -446,7 +436,7 @@ VM.prototype.reset = function(callback) { VM.prototype.setMetadata = function(metadata, callback) { var self = this; - callback = callback || util.noop; + callback = callback || common.util.noop; this.getMetadata(function(err, currentMetadata, apiResponse) { if (err) { @@ -510,7 +500,7 @@ VM.prototype.setTags = function(tags, fingerprint, callback) { method: 'POST', uri: '/setTags', json: body - }, callback || util.noop); + }, callback || common.util.noop); }; /** @@ -534,7 +524,7 @@ VM.prototype.start = function(callback) { this.request({ method: 'POST', uri: '/start' - }, callback || util.noop); + }, callback || common.util.noop); }; /** @@ -558,7 +548,7 @@ VM.prototype.stop = function(callback) { this.request({ method: 'POST', uri: '/stop' - }, callback || util.noop); + }, callback || common.util.noop); }; /** @@ -581,7 +571,9 @@ VM.prototype.stop = function(callback) { VM.prototype.request = function(reqOpts, callback) { var zone = this.zone; - ServiceObject.prototype.request.call(this, reqOpts, function(err, resp) { + var request = common.ServiceObject.prototype.request; + + request.call(this, reqOpts, function(err, resp) { if (err) { callback(err, null, resp); return; diff --git a/packages/google-cloud-compute/src/zone.js b/packages/google-cloud-compute/src/zone.js index 761a3db532d..2312131bc5f 100644 --- a/packages/google-cloud-compute/src/zone.js +++ b/packages/google-cloud-compute/src/zone.js @@ -27,7 +27,7 @@ var extend = require('extend'); var format = require('string-format-obj'); var gceImages = require('gce-images'); var is = require('is'); -var nodeutil = require('util'); +var util = require('util'); /** * @type {module:compute/autoscaler} @@ -59,18 +59,6 @@ var MachineType = require('./machine-type.js'); */ var Operation = require('./operation.js'); -/** - * @type {module:common/service-object} - * @private - */ -var ServiceObject = common.ServiceObject; - -/** - * @type {module:common/stream-router} - * @private - */ -var streamRouter = common.streamRouter; - /** * @type {module:compute/vm} * @private @@ -144,7 +132,7 @@ function Zone(compute, name) { getMetadata: true }; - ServiceObject.call(this, { + common.ServiceObject.call(this, { parent: compute, baseUrl: '/zones', id: name, @@ -159,7 +147,7 @@ function Zone(compute, name) { }); } -nodeutil.inherits(Zone, ServiceObject); +util.inherits(Zone, common.ServiceObject); /** * Get a reference to a Google Compute Engine autoscaler in this zone. @@ -1400,7 +1388,7 @@ Zone.prototype.createHttpsServerFirewall_ = function(callback) { * These methods can be used with either a callback or as a readable object * stream. `streamRouter` is used to add this dual behavior. */ -streamRouter.extend(Zone, [ +common.streamRouter.extend(Zone, [ 'getAutoscalers', 'getDisks', 'getInstanceGroups', diff --git a/packages/google-cloud-compute/system-test/compute.js b/packages/google-cloud-compute/system-test/compute.js index 1924b6f8259..f7847e35e92 100644 --- a/packages/google-cloud-compute/system-test/compute.js +++ b/packages/google-cloud-compute/system-test/compute.js @@ -1005,6 +1005,86 @@ describe('Compute', function() { }); }); + describe('subnetworks', function() { + var NETWORK_NAME = generateName('network'); + var network = compute.network(NETWORK_NAME); + + var SUBNETWORK_NAME = generateName('subnetwork'); + var subnetwork = region.subnetwork(SUBNETWORK_NAME); + + var NETWORK_CONFIG = { + autoCreateSubnetworks: false + }; + + var SUBNETWORK_CONFIG = { + network: 'global/networks/' + NETWORK_NAME, + range: '10.0.1.0/24' + }; + + before(function(done) { + async.series([ + create(network, NETWORK_CONFIG), + create(subnetwork, SUBNETWORK_CONFIG) + ], done); + }); + + it('should have created the subnetwork', function(done) { + subnetwork.getMetadata(function(err, metadata) { + assert.ifError(err); + assert.strictEqual(metadata.name, SUBNETWORK_NAME); + done(); + }); + }); + + it('should get a list of subnetworks', function(done) { + compute.getSubnetworks(function(err, subnetworks) { + assert.ifError(err); + assert(subnetworks.length > 0); + done(); + }); + }); + + it('should get a list of subnetworks in stream mode', function(done) { + var resultsMatched = 0; + + compute.getSubnetworks() + .on('error', done) + .on('data', function() { + resultsMatched++; + }) + .on('end', function() { + assert(resultsMatched > 0); + done(); + }); + }); + + it('should get a list of regional subnetworks', function(done) { + region.getSubnetworks(function(err, subnetworks) { + assert.ifError(err); + assert(subnetworks.length > 0); + done(); + }); + }); + + it('should get a list of regional subnetworks in stream', function(done) { + var resultsMatched = 0; + + region.getSubnetworks() + .on('error', done) + .on('data', function() { + resultsMatched++; + }) + .on('end', function() { + assert(resultsMatched > 0); + done(); + }); + }); + + it('should access a subnetwork through a Region', function(done) { + region.subnetwork(SUBNETWORK_NAME).getMetadata(done); + }); + }); + describe('vms', function() { var VM_NAME = generateName('vm'); var vm = zone.vm(VM_NAME); @@ -1201,86 +1281,6 @@ describe('Compute', function() { }); }); - describe('subnetworks', function() { - var NETWORK_NAME = generateName('network'); - var network = compute.network(NETWORK_NAME); - - var SUBNETWORK_NAME = generateName('subnetwork'); - var subnetwork = region.subnetwork(SUBNETWORK_NAME); - - var NETWORK_CONFIG = { - autoCreateSubnetworks: false - }; - - var SUBNETWORK_CONFIG = { - network: 'global/networks/' + NETWORK_NAME, - range: '10.0.1.0/24' - }; - - before(function(done) { - async.series([ - create(network, NETWORK_CONFIG), - create(subnetwork, SUBNETWORK_CONFIG) - ], done); - }); - - it('should have created the subnetwork', function(done) { - subnetwork.getMetadata(function(err, metadata) { - assert.ifError(err); - assert.strictEqual(metadata.name, SUBNETWORK_NAME); - done(); - }); - }); - - it('should get a list of subnetworks', function(done) { - compute.getSubnetworks(function(err, subnetworks) { - assert.ifError(err); - assert(subnetworks.length > 0); - done(); - }); - }); - - it('should get a list of subnetworks in stream mode', function(done) { - var resultsMatched = 0; - - compute.getSubnetworks() - .on('error', done) - .on('data', function() { - resultsMatched++; - }) - .on('end', function() { - assert(resultsMatched > 0); - done(); - }); - }); - - it('should get a list of regional subnetworks', function(done) { - region.getSubnetworks(function(err, subnetworks) { - assert.ifError(err); - assert(subnetworks.length > 0); - done(); - }); - }); - - it('should get a list of regional subnetworks in stream', function(done) { - var resultsMatched = 0; - - region.getSubnetworks() - .on('error', done) - .on('data', function() { - resultsMatched++; - }) - .on('end', function() { - assert(resultsMatched > 0); - done(); - }); - }); - - it('should access a subnetwork through a Region', function(done) { - region.subnetwork(SUBNETWORK_NAME).getMetadata(done); - }); - }); - function generateName(customPrefix) { return TESTS_PREFIX + customPrefix + '-' + Date.now(); } diff --git a/packages/google-cloud-compute/test/address.js b/packages/google-cloud-compute/test/address.js index 13745245515..cbc7f2018f9 100644 --- a/packages/google-cloud-compute/test/address.js +++ b/packages/google-cloud-compute/test/address.js @@ -20,7 +20,6 @@ var assert = require('assert'); var extend = require('extend'); var nodeutil = require('util'); var proxyquire = require('proxyquire'); - var ServiceObject = require('@google-cloud/common').ServiceObject; var util = require('@google-cloud/common').util; diff --git a/packages/google-cloud-compute/test/autoscaler.js b/packages/google-cloud-compute/test/autoscaler.js index 5d83148092d..2426f18a3b8 100644 --- a/packages/google-cloud-compute/test/autoscaler.js +++ b/packages/google-cloud-compute/test/autoscaler.js @@ -20,7 +20,6 @@ var assert = require('assert'); var extend = require('extend'); var nodeutil = require('util'); var proxyquire = require('proxyquire'); - var ServiceObject = require('@google-cloud/common').ServiceObject; var util = require('@google-cloud/common').util; diff --git a/packages/google-cloud-compute/test/disk.js b/packages/google-cloud-compute/test/disk.js index bbb2f89760e..3efd71c3b84 100644 --- a/packages/google-cloud-compute/test/disk.js +++ b/packages/google-cloud-compute/test/disk.js @@ -19,9 +19,8 @@ var assert = require('assert'); var extend = require('extend'); var format = require('string-format-obj'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; var util = require('@google-cloud/common').util; diff --git a/packages/google-cloud-compute/test/firewall.js b/packages/google-cloud-compute/test/firewall.js index 124013e4a08..8a121662e37 100644 --- a/packages/google-cloud-compute/test/firewall.js +++ b/packages/google-cloud-compute/test/firewall.js @@ -18,9 +18,8 @@ var assert = require('assert'); var extend = require('extend'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; var util = require('@google-cloud/common').util; diff --git a/packages/google-cloud-compute/test/health-check.js b/packages/google-cloud-compute/test/health-check.js index 00c9382a177..229c400fa49 100644 --- a/packages/google-cloud-compute/test/health-check.js +++ b/packages/google-cloud-compute/test/health-check.js @@ -18,9 +18,8 @@ var assert = require('assert'); var extend = require('extend'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; var util = require('@google-cloud/common').util; diff --git a/packages/google-cloud-compute/test/index.js b/packages/google-cloud-compute/test/index.js index f31c22de79a..65ccd810a0f 100644 --- a/packages/google-cloud-compute/test/index.js +++ b/packages/google-cloud-compute/test/index.js @@ -19,11 +19,11 @@ var arrify = require('arrify'); var assert = require('assert'); var extend = require('extend'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var Service = require('@google-cloud/common').Service; var util = require('@google-cloud/common').util; + var PKG = require('../package.json'); var slice = Array.prototype.slice; diff --git a/packages/google-cloud-compute/test/instance-group.js b/packages/google-cloud-compute/test/instance-group.js index 25d69802129..3dc4faa5d3c 100644 --- a/packages/google-cloud-compute/test/instance-group.js +++ b/packages/google-cloud-compute/test/instance-group.js @@ -19,8 +19,8 @@ var arrify = require('arrify'); var assert = require('assert'); var extend = require('extend'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; var util = require('@google-cloud/common').util; diff --git a/packages/google-cloud-compute/test/machine-type.js b/packages/google-cloud-compute/test/machine-type.js index 456d8293168..5cbe17b04cc 100644 --- a/packages/google-cloud-compute/test/machine-type.js +++ b/packages/google-cloud-compute/test/machine-type.js @@ -17,9 +17,8 @@ 'use strict'; var assert = require('assert'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; function FakeServiceObject() { diff --git a/packages/google-cloud-compute/test/network.js b/packages/google-cloud-compute/test/network.js index f5ec67a2cf8..228c421aff3 100644 --- a/packages/google-cloud-compute/test/network.js +++ b/packages/google-cloud-compute/test/network.js @@ -19,9 +19,8 @@ var assert = require('assert'); var extend = require('extend'); var format = require('string-format-obj'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; var util = require('@google-cloud/common').util; diff --git a/packages/google-cloud-compute/test/operation.js b/packages/google-cloud-compute/test/operation.js index e966dca7e10..6d598224c31 100644 --- a/packages/google-cloud-compute/test/operation.js +++ b/packages/google-cloud-compute/test/operation.js @@ -18,9 +18,8 @@ var assert = require('assert'); var extend = require('extend'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; var util = require('@google-cloud/common').util; diff --git a/packages/google-cloud-compute/test/region.js b/packages/google-cloud-compute/test/region.js index 899fde187a6..77f200c9cf5 100644 --- a/packages/google-cloud-compute/test/region.js +++ b/packages/google-cloud-compute/test/region.js @@ -20,28 +20,23 @@ var arrify = require('arrify'); var assert = require('assert'); var extend = require('extend'); var is = require('is'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; function FakeAddress() { this.calledWith_ = [].slice.call(arguments); } -function FakeOperation() { - this.calledWith_ = [].slice.call(arguments); -} - -function FakeRule() { +function FakeNetwork() { this.calledWith_ = [].slice.call(arguments); } -function FakeNetwork() { +function FakeOperation() { this.calledWith_ = [].slice.call(arguments); } -function FakeSubnetwork() { +function FakeRule() { this.calledWith_ = [].slice.call(arguments); } @@ -50,6 +45,10 @@ function FakeServiceObject() { ServiceObject.apply(this, arguments); } +function FakeSubnetwork() { + this.calledWith_ = [].slice.call(arguments); +} + nodeutil.inherits(FakeServiceObject, ServiceObject); var extended = false; @@ -65,7 +64,8 @@ var fakeStreamRouter = { assert.deepEqual(methods, [ 'getAddresses', 'getOperations', - 'getRules', 'getSubnetworks' + 'getRules', + 'getSubnetworks' ]); } }; diff --git a/packages/google-cloud-compute/test/rule.js b/packages/google-cloud-compute/test/rule.js index d4648b27a3e..50e3fff97ad 100644 --- a/packages/google-cloud-compute/test/rule.js +++ b/packages/google-cloud-compute/test/rule.js @@ -19,7 +19,6 @@ var assert = require('assert'); var extend = require('extend'); var proxyquire = require('proxyquire'); - var util = require('@google-cloud/common').util; function FakeServiceObject() { diff --git a/packages/google-cloud-compute/test/service.js b/packages/google-cloud-compute/test/service.js index 8f98db12c1a..b0bc42c5d80 100644 --- a/packages/google-cloud-compute/test/service.js +++ b/packages/google-cloud-compute/test/service.js @@ -18,9 +18,8 @@ var assert = require('assert'); var extend = require('extend'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; var util = require('@google-cloud/common').util; diff --git a/packages/google-cloud-compute/test/snapshot.js b/packages/google-cloud-compute/test/snapshot.js index fc4dff8a580..0099e3cc284 100644 --- a/packages/google-cloud-compute/test/snapshot.js +++ b/packages/google-cloud-compute/test/snapshot.js @@ -17,9 +17,8 @@ 'use strict'; var assert = require('assert'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; function FakeServiceObject() { diff --git a/packages/google-cloud-compute/test/subnetwork.js b/packages/google-cloud-compute/test/subnetwork.js index 504db667258..77e88a9f748 100644 --- a/packages/google-cloud-compute/test/subnetwork.js +++ b/packages/google-cloud-compute/test/subnetwork.js @@ -18,9 +18,8 @@ var assert = require('assert'); var extend = require('extend'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; var util = require('@google-cloud/common').util; diff --git a/packages/google-cloud-compute/test/vm.js b/packages/google-cloud-compute/test/vm.js index 12d53e48b5d..281a7fa2137 100644 --- a/packages/google-cloud-compute/test/vm.js +++ b/packages/google-cloud-compute/test/vm.js @@ -18,11 +18,10 @@ var assert = require('assert'); var extend = require('extend'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - -var util = require('@google-cloud/common').util; +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; +var util = require('@google-cloud/common').util; function FakeServiceObject() { this.calledWith_ = arguments; diff --git a/packages/google-cloud-compute/test/zone.js b/packages/google-cloud-compute/test/zone.js index 41ea92be5d0..78f911bf2b8 100644 --- a/packages/google-cloud-compute/test/zone.js +++ b/packages/google-cloud-compute/test/zone.js @@ -20,9 +20,8 @@ var arrify = require('arrify'); var assert = require('assert'); var extend = require('extend'); var gceImages = require('gce-images'); -var proxyquire = require('proxyquire'); var nodeutil = require('util'); - +var proxyquire = require('proxyquire'); var ServiceObject = require('@google-cloud/common').ServiceObject; var util = require('@google-cloud/common').util;