diff --git a/packages/bigquery/package.json b/packages/bigquery/package.json index 8f406993eda..f7351a68f10 100644 --- a/packages/bigquery/package.json +++ b/packages/bigquery/package.json @@ -50,7 +50,7 @@ "bigquery" ], "dependencies": { - "@google-cloud/common": "^0.4.0", + "@google-cloud/common": "^0.5.0", "arrify": "^1.0.0", "duplexify": "^3.2.0", "extend": "^3.0.0", diff --git a/packages/bigquery/src/index.js b/packages/bigquery/src/index.js index e343b51eb2f..38bd11d82fb 100644 --- a/packages/bigquery/src/index.js +++ b/packages/bigquery/src/index.js @@ -43,8 +43,6 @@ var Job = require('./job.js'); */ var Table = require('./table.js'); -var PKG = require('../package.json'); - /** * In the following examples from this page and the other modules (`Dataset`, * `Table`, etc.), we are going to be using a dataset from @@ -69,7 +67,7 @@ function BigQuery(options) { var config = { baseUrl: 'https://www.googleapis.com/bigquery/v2', scopes: ['https://www.googleapis.com/auth/bigquery'], - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }; common.Service.call(this, config, options); diff --git a/packages/bigquery/test/index.js b/packages/bigquery/test/index.js index aeecc0bb273..bd91873e209 100644 --- a/packages/bigquery/test/index.js +++ b/packages/bigquery/test/index.js @@ -26,8 +26,6 @@ var Service = require('@google-cloud/common').Service; var Table = require('../src/table.js'); var util = require('@google-cloud/common').util; -var PKG = require('../package.json'); - var fakeUtil = extend({}, util); function FakeTable(a, b) { @@ -118,7 +116,7 @@ describe('BigQuery', function() { assert.deepEqual(calledWith.scopes, [ 'https://www.googleapis.com/auth/bigquery' ]); - assert.strictEqual(calledWith.userAgent, PKG.name + '/' + PKG.version); + assert.deepEqual(calledWith.packageJson, require('../package.json')); }); }); diff --git a/packages/bigtable/package.json b/packages/bigtable/package.json index 901459a5d83..9d1eb93478b 100644 --- a/packages/bigtable/package.json +++ b/packages/bigtable/package.json @@ -50,7 +50,7 @@ "bigtable" ], "dependencies": { - "@google-cloud/common": "^0.4.0", + "@google-cloud/common": "^0.5.0", "arrify": "^1.0.0", "concat-stream": "^1.5.0", "create-error-class": "^3.0.2", diff --git a/packages/bigtable/src/index.js b/packages/bigtable/src/index.js index 6bb8b1cabc5..8bde933bbaf 100644 --- a/packages/bigtable/src/index.js +++ b/packages/bigtable/src/index.js @@ -29,17 +29,15 @@ var util = require('util'); /** * @private - * @type {module:bigtable/instance} + * @type {module:bigtable/cluster} */ -var Instance = require('./instance.js'); +var Cluster = require('./cluster.js'); /** * @private - * @type {module:bigtable/cluster} + * @type {module:bigtable/instance} */ -var Cluster = require('./cluster.js'); - -var PKG = require('../package.json'); +var Instance = require('./instance.js'); /** * @alias module:bigtable @@ -319,7 +317,7 @@ function Bigtable(options) { 'https://www.googleapis.com/auth/bigtable.data', 'https://www.googleapis.com/auth/cloud-platform' ], - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }; common.GrpcService.call(this, config, options); diff --git a/packages/bigtable/test/index.js b/packages/bigtable/test/index.js index 6b719f21525..b548e7ce9f3 100644 --- a/packages/bigtable/test/index.js +++ b/packages/bigtable/test/index.js @@ -26,7 +26,6 @@ var sinon = require('sinon').sandbox.create(); var common = require('@google-cloud/common'); var Cluster = require('../src/cluster.js'); var Instance = require('../src/instance.js'); -var PKG = require('../package.json'); var fakeUtil = extend({}, common.util); var fakeStreamRouter = { @@ -143,7 +142,7 @@ describe('Bigtable', function() { 'https://www.googleapis.com/auth/cloud-platform' ]); - assert.strictEqual(calledWith.userAgent, PKG.name + '/' + PKG.version); + assert.deepEqual(calledWith.packageJson, require('../package.json')); }); it('should set the projectName', function() { diff --git a/packages/compute/package.json b/packages/compute/package.json index 77ca0ee8ab9..bfbc21288c7 100644 --- a/packages/compute/package.json +++ b/packages/compute/package.json @@ -50,7 +50,7 @@ "compute engine" ], "dependencies": { - "@google-cloud/common": "^0.1.0", + "@google-cloud/common": "^0.5.0", "arrify": "^1.0.0", "async": "^1.4.2", "create-error-class": "^2.0.1", diff --git a/packages/compute/src/index.js b/packages/compute/src/index.js index f282f756754..59b34da1662 100644 --- a/packages/compute/src/index.js +++ b/packages/compute/src/index.js @@ -80,8 +80,6 @@ var Snapshot = require('./snapshot.js'); */ var Zone = require('./zone.js'); -var PKG = require('../package.json'); - /** * @alias module:compute * @constructor @@ -99,7 +97,7 @@ function Compute(options) { var config = { baseUrl: 'https://www.googleapis.com/compute/v1', scopes: ['https://www.googleapis.com/auth/compute'], - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }; common.Service.call(this, config, options); diff --git a/packages/compute/test/index.js b/packages/compute/test/index.js index 96bcfed0e52..0c658accb2b 100644 --- a/packages/compute/test/index.js +++ b/packages/compute/test/index.js @@ -25,8 +25,6 @@ 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; var fakeUtil = extend({}, util, { @@ -183,7 +181,7 @@ describe('Compute', function() { assert.deepEqual(calledWith.scopes, [ 'https://www.googleapis.com/auth/compute' ]); - assert.strictEqual(calledWith.userAgent, PKG.name + '/' + PKG.version); + assert.deepEqual(calledWith.packageJson, require('../package.json')); }); }); diff --git a/packages/datastore/package.json b/packages/datastore/package.json index eed4f3a7e56..2ff94495a94 100644 --- a/packages/datastore/package.json +++ b/packages/datastore/package.json @@ -50,7 +50,7 @@ "datastore" ], "dependencies": { - "@google-cloud/common": "^0.4.0", + "@google-cloud/common": "^0.5.0", "arrify": "^1.0.0", "concat-stream": "^1.5.0", "create-error-class": "^3.0.2", diff --git a/packages/datastore/src/index.js b/packages/datastore/src/index.js index b73f36d446c..0bef77f26a7 100644 --- a/packages/datastore/src/index.js +++ b/packages/datastore/src/index.js @@ -49,8 +49,6 @@ var Query = require('./query.js'); */ var Transaction = require('./transaction.js'); -var PKG = require('../package.json'); - /** * @constructor * @alias module:datastore @@ -323,7 +321,7 @@ function Datastore(options) { service: 'datastore', apiVersion: 'v1', scopes: ['https://www.googleapis.com/auth/datastore'], - userAgent: PKG.name + '/' + PKG.version, + packageJson: require('../package.json'), grpcMetadata: { 'google-cloud-resource-prefix': 'projects/' + this.projectId } diff --git a/packages/datastore/test/index.js b/packages/datastore/test/index.js index 64e3e1544bb..ad7161ecf32 100644 --- a/packages/datastore/test/index.js +++ b/packages/datastore/test/index.js @@ -21,8 +21,6 @@ var extend = require('extend'); var proxyquire = require('proxyquire'); var util = require('@google-cloud/common').util; -var PKG = require('../package.json'); - var fakeEntity = { Int: function(value) { this.value = value; @@ -157,7 +155,7 @@ describe('Datastore', function() { assert.deepEqual(calledWith.scopes, [ 'https://www.googleapis.com/auth/datastore' ]); - assert.strictEqual(calledWith.userAgent, PKG.name + '/' + PKG.version); + assert.deepEqual(calledWith.packageJson, require('../package.json')); assert.deepEqual(calledWith.grpcMetadata, { 'google-cloud-resource-prefix': 'projects/' + datastore.projectId }); diff --git a/packages/dns/package.json b/packages/dns/package.json index 0f95be64d53..4e98acf784f 100644 --- a/packages/dns/package.json +++ b/packages/dns/package.json @@ -50,7 +50,7 @@ "dns" ], "dependencies": { - "@google-cloud/common": "^0.1.0", + "@google-cloud/common": "^0.5.0", "arrify": "^1.0.0", "dns-zonefile": "0.1.18", "extend": "^3.0.0", diff --git a/packages/dns/src/index.js b/packages/dns/src/index.js index ffb13b0f149..c04c552aaa1 100644 --- a/packages/dns/src/index.js +++ b/packages/dns/src/index.js @@ -32,8 +32,6 @@ var util = require('util'); */ var Zone = require('./zone.js'); -var PKG = require('../package.json'); - /** * [Google Cloud DNS](https://cloud.google.com/dns/what-is-cloud-dns) is a high- * performance, resilient, global DNS service that provides a cost-effective way @@ -60,7 +58,7 @@ function DNS(options) { 'https://www.googleapis.com/auth/ndev.clouddns.readwrite', 'https://www.googleapis.com/auth/cloud-platform' ], - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }; common.Service.call(this, config, options); diff --git a/packages/dns/test/index.js b/packages/dns/test/index.js index 5cb87ec79fa..9aa5a5e4a2c 100644 --- a/packages/dns/test/index.js +++ b/packages/dns/test/index.js @@ -24,8 +24,6 @@ var proxyquire = require('proxyquire'); var Service = require('@google-cloud/common').Service; var util = require('@google-cloud/common').util; -var PKG = require('../package.json'); - var extended = false; var fakeStreamRouter = { extend: function(Class, methods) { @@ -113,7 +111,7 @@ describe('DNS', function() { 'https://www.googleapis.com/auth/ndev.clouddns.readwrite', 'https://www.googleapis.com/auth/cloud-platform' ]); - assert.strictEqual(calledWith.userAgent, PKG.name + '/' + PKG.version); + assert.deepEqual(calledWith.packageJson, require('../package.json')); }); }); diff --git a/packages/language/package.json b/packages/language/package.json index 4b847782336..0b82858c26b 100644 --- a/packages/language/package.json +++ b/packages/language/package.json @@ -52,7 +52,7 @@ "language" ], "dependencies": { - "@google-cloud/common": "^0.4.0", + "@google-cloud/common": "^0.5.0", "arguejs": "^0.2.3", "arrify": "^1.0.1", "extend": "^3.0.0", diff --git a/packages/language/src/index.js b/packages/language/src/index.js index 3eb43b5f9c8..1c8fa896bdd 100644 --- a/packages/language/src/index.js +++ b/packages/language/src/index.js @@ -32,8 +32,6 @@ var util = require('util'); */ var Document = require('./document.js'); -var PKG = require('../package.json'); - /** *
* **This is a Beta release of Google Cloud Natural Language.** This API is @@ -79,7 +77,7 @@ function Language(options) { scopes: [ 'https://www.googleapis.com/auth/cloud-platform' ], - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }; common.GrpcService.call(this, config, options); diff --git a/packages/language/test/index.js b/packages/language/test/index.js index 13a9af7d227..535a3e1ccd9 100644 --- a/packages/language/test/index.js +++ b/packages/language/test/index.js @@ -22,8 +22,6 @@ var googleProtoFiles = require('google-proto-files'); var proxyquire = require('proxyquire'); var util = require('@google-cloud/common').util; -var PKG = require('../package.json'); - var fakeUtil = extend(true, {}, util); function FakeDocument() { @@ -98,7 +96,7 @@ describe('Language', function() { scopes: [ 'https://www.googleapis.com/auth/cloud-platform' ], - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }); }); }); diff --git a/packages/logging/package.json b/packages/logging/package.json index 148c9afb519..2137fcc173e 100644 --- a/packages/logging/package.json +++ b/packages/logging/package.json @@ -52,7 +52,7 @@ "stackdriver" ], "dependencies": { - "@google-cloud/common": "^0.4.0", + "@google-cloud/common": "^0.5.0", "arguejs": "^0.2.3", "arrify": "^1.0.0", "extend": "^3.0.0", diff --git a/packages/logging/src/index.js b/packages/logging/src/index.js index d52885a3410..c20563681cd 100644 --- a/packages/logging/src/index.js +++ b/packages/logging/src/index.js @@ -46,8 +46,6 @@ var Log = require('./log.js'); */ var Sink = require('./sink.js'); -var PKG = require('../package.json'); - /** *
* **This is a Beta release of Stackdriver Logging.** This API is not covered @@ -85,7 +83,7 @@ function Logging(options) { scopes: [ 'https://www.googleapis.com/auth/cloud-platform' ], - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }; common.GrpcService.call(this, config, options); diff --git a/packages/logging/test/index.js b/packages/logging/test/index.js index 215a88c3ab0..a5cacbd4123 100644 --- a/packages/logging/test/index.js +++ b/packages/logging/test/index.js @@ -23,8 +23,6 @@ var googleProtoFiles = require('google-proto-files'); var proxyquire = require('proxyquire'); var util = require('@google-cloud/common').util; -var PKG = require('../package.json'); - var extended = false; var fakeStreamRouter = { extend: function(Class, methods) { @@ -147,7 +145,7 @@ describe('Logging', function() { assert.deepEqual(calledWith.scopes, [ 'https://www.googleapis.com/auth/cloud-platform' ]); - assert.strictEqual(calledWith.userAgent, PKG.name + '/' + PKG.version); + assert.deepEqual(calledWith.packageJson, require('../package.json')); }); }); diff --git a/packages/prediction/package.json b/packages/prediction/package.json index e6739988f77..f888d087fa0 100644 --- a/packages/prediction/package.json +++ b/packages/prediction/package.json @@ -50,7 +50,7 @@ "prediction" ], "dependencies": { - "@google-cloud/common": "^0.1.0", + "@google-cloud/common": "^0.5.0", "JSONStream": "^1.0.7", "arrify": "^1.0.0", "extend": "^3.0.0", diff --git a/packages/prediction/src/index.js b/packages/prediction/src/index.js index a53df586fbc..eecb91d930c 100644 --- a/packages/prediction/src/index.js +++ b/packages/prediction/src/index.js @@ -33,8 +33,6 @@ var util = require('util'); */ var Model = require('./model.js'); -var PKG = require('../package.json'); - /** * The [Google Prediction API](https://cloud.google.com/prediction/docs/getting-started) * provides pattern-matching and machine learning capabilities. Given a set of @@ -70,7 +68,7 @@ function Prediction(options) { 'https://www.googleapis.com/auth/prediction', 'https://www.googleapis.com/auth/devstorage.read_only' ], - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }; common.Service.call(this, config, options); diff --git a/packages/prediction/test/index.js b/packages/prediction/test/index.js index 283c418ee04..22111064f44 100644 --- a/packages/prediction/test/index.js +++ b/packages/prediction/test/index.js @@ -24,8 +24,6 @@ var proxyquire = require('proxyquire'); var Service = require('@google-cloud/common').Service; var util = require('@google-cloud/common').util; -var PKG = require('../package.json'); - function FakeModel() { this.calledWith_ = arguments; } @@ -114,7 +112,7 @@ describe('Prediction', function() { 'https://www.googleapis.com/auth/prediction', 'https://www.googleapis.com/auth/devstorage.read_only' ]); - assert.strictEqual(calledWith.userAgent, PKG.name + '/' + PKG.version); + assert.deepEqual(calledWith.packageJson, require('../package.json')); }); }); diff --git a/packages/pubsub/package.json b/packages/pubsub/package.json index cf6decc3391..8f9fed2b64b 100644 --- a/packages/pubsub/package.json +++ b/packages/pubsub/package.json @@ -50,7 +50,7 @@ "pubsub" ], "dependencies": { - "@google-cloud/common": "^0.4.0", + "@google-cloud/common": "^0.5.0", "arguejs": "^0.2.3", "arrify": "^1.0.0", "extend": "^3.0.0", diff --git a/packages/pubsub/src/iam.js b/packages/pubsub/src/iam.js index 036e5e8751a..30501f8471d 100644 --- a/packages/pubsub/src/iam.js +++ b/packages/pubsub/src/iam.js @@ -73,7 +73,8 @@ function IAM(pubsub, id) { scopes: [ 'https://www.googleapis.com/auth/pubsub', 'https://www.googleapis.com/auth/cloud-platform' - ] + ], + packageJson: require('../package.json') }; this.id = id; diff --git a/packages/pubsub/src/index.js b/packages/pubsub/src/index.js index 8a5b237c62c..d76f4968a95 100644 --- a/packages/pubsub/src/index.js +++ b/packages/pubsub/src/index.js @@ -38,8 +38,6 @@ var Subscription = require('./subscription.js'); */ var Topic = require('./topic.js'); -var PKG = require('../package.json'); - /** * [Google Cloud Pub/Sub](https://developers.google.com/pubsub/overview) is a * reliable, many-to-many, asynchronous messaging service from Google Cloud @@ -73,7 +71,7 @@ function PubSub(options) { 'https://www.googleapis.com/auth/pubsub', 'https://www.googleapis.com/auth/cloud-platform' ], - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }; this.options = options; diff --git a/packages/pubsub/test/iam.js b/packages/pubsub/test/iam.js index dc394497ddb..d13eda5c7d3 100644 --- a/packages/pubsub/test/iam.js +++ b/packages/pubsub/test/iam.js @@ -65,6 +65,7 @@ describe('IAM', function() { 'https://www.googleapis.com/auth/pubsub', 'https://www.googleapis.com/auth/cloud-platform' ]); + assert.deepEqual(config.packageJson, require('../package.json')); assert.strictEqual(options, PUBSUB.options); }); diff --git a/packages/pubsub/test/index.js b/packages/pubsub/test/index.js index f4c72c91947..111e31f098e 100644 --- a/packages/pubsub/test/index.js +++ b/packages/pubsub/test/index.js @@ -22,8 +22,6 @@ var extend = require('extend'); var proxyquire = require('proxyquire'); var util = require('@google-cloud/common').util; -var PKG = require('../package.json'); - var SubscriptionCached = require('../src/subscription.js'); var SubscriptionOverride; @@ -124,7 +122,7 @@ describe('PubSub', function() { 'https://www.googleapis.com/auth/pubsub', 'https://www.googleapis.com/auth/cloud-platform' ]); - assert.strictEqual(calledWith.userAgent, PKG.name + '/' + PKG.version); + assert.deepEqual(calledWith.packageJson, require('../package.json')); }); it('should set the defaultBaseUrl_', function() { diff --git a/packages/resource/package.json b/packages/resource/package.json index 37d969c7e4e..b9e35b85edc 100644 --- a/packages/resource/package.json +++ b/packages/resource/package.json @@ -50,7 +50,7 @@ "resource" ], "dependencies": { - "@google-cloud/common": "^0.1.0", + "@google-cloud/common": "^0.5.0", "extend": "^3.0.0", "is": "^3.0.1" }, diff --git a/packages/resource/src/index.js b/packages/resource/src/index.js index 88f0134cf29..0a9df2fdd31 100644 --- a/packages/resource/src/index.js +++ b/packages/resource/src/index.js @@ -31,8 +31,6 @@ var util = require('util'); */ var Project = require('./project.js'); -var PKG = require('../package.json'); - /** *
* **This is a Beta release of Cloud Resource Manager.** This feature is not @@ -69,7 +67,7 @@ function Resource(options) { baseUrl: 'https://cloudresourcemanager.googleapis.com/v1beta1', scopes: ['https://www.googleapis.com/auth/cloud-platform'], projectIdRequired: false, - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }; common.Service.call(this, config, options); diff --git a/packages/resource/test/index.js b/packages/resource/test/index.js index d0ac5dc8631..07a39e6adf5 100644 --- a/packages/resource/test/index.js +++ b/packages/resource/test/index.js @@ -24,8 +24,6 @@ var proxyquire = require('proxyquire'); var Service = require('@google-cloud/common').Service; var util = require('@google-cloud/common').util; -var PKG = require('../package.json'); - function FakeProject() { this.calledWith_ = [].slice.call(arguments); } @@ -126,7 +124,7 @@ describe('Resource', function() { 'https://www.googleapis.com/auth/cloud-platform' ]); assert.strictEqual(resource.projectIdRequired, false); - assert.strictEqual(calledWith.userAgent, PKG.name + '/' + PKG.version); + assert.deepEqual(calledWith.packageJson, require('../package.json')); }); }); diff --git a/packages/storage/package.json b/packages/storage/package.json index fae6ce61107..425b7c814c3 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -50,7 +50,7 @@ "storage" ], "dependencies": { - "@google-cloud/common": "^0.1.0", + "@google-cloud/common": "^0.5.0", "arrify": "^1.0.0", "async": "^1.4.2", "concat-stream": "^1.5.0", diff --git a/packages/storage/src/index.js b/packages/storage/src/index.js index 7ebb266e8c9..7531f884ed4 100644 --- a/packages/storage/src/index.js +++ b/packages/storage/src/index.js @@ -43,8 +43,6 @@ var Channel = require('./channel.js'); */ var File = require('./file.js'); -var PKG = require('../package.json'); - /*! Developer Documentation * * Invoke this method to create a new Storage object bound with pre-determined @@ -83,7 +81,7 @@ function Storage(options) { scopes: [ 'https://www.googleapis.com/auth/devstorage.full_control' ], - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }; common.Service.call(this, config, options); diff --git a/packages/storage/test/index.js b/packages/storage/test/index.js index b581c73c5ed..178a6fc19ed 100644 --- a/packages/storage/test/index.js +++ b/packages/storage/test/index.js @@ -24,8 +24,6 @@ var proxyquire = require('proxyquire'); var Service = require('@google-cloud/common').Service; var util = require('@google-cloud/common').util; -var PKG = require('../package.json'); - function FakeChannel() { this.calledWith_ = arguments; } @@ -110,7 +108,7 @@ describe('Storage', function() { assert.deepEqual(calledWith.scopes, [ 'https://www.googleapis.com/auth/devstorage.full_control' ]); - assert.strictEqual(calledWith.userAgent, PKG.name + '/' + PKG.version); + assert.deepEqual(calledWith.packageJson, require('../package.json')); }); }); diff --git a/packages/translate/package.json b/packages/translate/package.json index 397f548e6e7..9de7d3b72dc 100644 --- a/packages/translate/package.json +++ b/packages/translate/package.json @@ -50,7 +50,7 @@ "translate" ], "dependencies": { - "@google-cloud/common": "^0.2.0", + "@google-cloud/common": "^0.5.0", "arrify": "^1.0.0", "extend": "^3.0.0", "is": "^3.0.1", diff --git a/packages/translate/src/index.js b/packages/translate/src/index.js index c05be0e6bf4..1db4ca5cbdb 100644 --- a/packages/translate/src/index.js +++ b/packages/translate/src/index.js @@ -384,7 +384,7 @@ Translate.prototype.request = function(reqOpts, callback) { key: this.key }, headers: { - 'User-Agent': PKG.name + '/' + PKG.version + 'User-Agent': common.util.getUserAgentFromPackageJson(PKG) } }); diff --git a/packages/translate/test/index.js b/packages/translate/test/index.js index b6969c9ff7f..bcd05f90ceb 100644 --- a/packages/translate/test/index.js +++ b/packages/translate/test/index.js @@ -21,8 +21,6 @@ var extend = require('extend'); var proxyquire = require('proxyquire'); var util = require('@google-cloud/common').util; -var PKG = require('../package.json'); - var makeRequestOverride; var fakeUtil = extend({}, util, { makeRequest: function() { @@ -386,6 +384,15 @@ describe('Translate', function() { describe('request', function() { it('should make the correct request', function(done) { + var userAgent = 'user-agent/0.0.0'; + + var getUserAgentFn = fakeUtil.getUserAgentFromPackageJson; + fakeUtil.getUserAgentFromPackageJson = function(packageJson) { + fakeUtil.getUserAgentFromPackageJson = getUserAgentFn; + assert.deepEqual(packageJson, require('../package.json')); + return userAgent; + }; + var reqOpts = { uri: '/test', a: 'b', @@ -401,7 +408,7 @@ describe('Translate', function() { key: translate.key }, headers: { - 'User-Agent': PKG.name + '/' + PKG.version + 'User-Agent': userAgent } }); var BASE_URL = 'https://www.googleapis.com/language/translate/v2'; diff --git a/packages/vision/package.json b/packages/vision/package.json index ab3040b3055..07f457bf0b8 100644 --- a/packages/vision/package.json +++ b/packages/vision/package.json @@ -50,7 +50,7 @@ "vision" ], "dependencies": { - "@google-cloud/common": "^0.3.0", + "@google-cloud/common": "^0.5.0", "arguejs": "^0.2.3", "arrify": "^1.0.0", "async": "^1.4.2", diff --git a/packages/vision/src/index.js b/packages/vision/src/index.js index c4b1255bcac..662c9e5151c 100644 --- a/packages/vision/src/index.js +++ b/packages/vision/src/index.js @@ -32,8 +32,6 @@ var request = require('request'); var rgbHex = require('rgb-hex'); var util = require('util'); -var PKG = require('../package.json'); - var VERY_UNLIKELY = 0; var UNLIKELY = 1; var POSSIBLE = 2; @@ -72,7 +70,7 @@ function Vision(options) { scopes: [ 'https://www.googleapis.com/auth/cloud-platform' ], - userAgent: PKG.name + '/' + PKG.version + packageJson: require('../package.json') }; common.Service.call(this, config, options); diff --git a/packages/vision/test/index.js b/packages/vision/test/index.js index 5862407e5d6..7790d726ac2 100644 --- a/packages/vision/test/index.js +++ b/packages/vision/test/index.js @@ -29,8 +29,6 @@ var Service = require('@google-cloud/common').Service; var tmp = require('tmp'); var util = require('@google-cloud/common').util; -var PKG = require('../package.json'); - var fakeUtil = extend({}, util); function FakeService() { @@ -101,7 +99,7 @@ describe('Vision', function() { assert.deepEqual(calledWith.scopes, [ 'https://www.googleapis.com/auth/cloud-platform' ]); - assert.strictEqual(calledWith.userAgent, PKG.name + '/' + PKG.version); + assert.deepEqual(calledWith.packageJson, require('../package.json')); }); });