From b05773b5f8c04da07d2c02ef98e441fe91d31216 Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Tue, 13 Dec 2016 15:51:32 -0800 Subject: [PATCH] Fixed linting issues --- packages/common/src/metadata.js | 10 ++++---- packages/common/test/metadata.js | 42 ++++++++++++++----------------- packages/common/test/paginator.js | 6 ++--- packages/common/test/util.js | 4 +-- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/packages/common/src/metadata.js b/packages/common/src/metadata.js index 037d75b4be58..f5f4a578773f 100644 --- a/packages/common/src/metadata.js +++ b/packages/common/src/metadata.js @@ -20,7 +20,6 @@ 'use strict'; -var request = require('request'); var util = require('./util.js'); var METADATA_URL = 'http://metadata.google.internal/computeMetadata/v1'; @@ -42,7 +41,7 @@ metadata.getMetadataValue = getMetadataValue; /** * Attempts to retreive the project id for the current active project from the * metadata service (See https://cloud.google.com/compute/docs/metadata). - * + * * @param {Object} [headers] - An optional set of headers to include in the http * request. This function may mutate the given headers object. * @param {function(?, number):?} callback an (err, result) style callback @@ -53,15 +52,16 @@ function getProjectId(headers, callback) { headers = {}; } getMetadataValue('/project/project-id', headers, - function (err, projectId, response) { + function(err, projectId, response) { if (!err && response.statusCode === 200) { return callback(null, projectId); - } else if (err && err.code === 'ENOTFOUND') { + } + if (err && err.code === 'ENOTFOUND') { return callback(new Error('Could not auto-discover project-id.' + 'Please export GCLOUD_PROJECT with your project name'), null); } return callback(err || new Error('Error discovering project id'), null); - }); + }); } metadata.getProjectId = getProjectId; diff --git a/packages/common/test/metadata.js b/packages/common/test/metadata.js index fc0887183087..672b09080ced 100644 --- a/packages/common/test/metadata.js +++ b/packages/common/test/metadata.js @@ -16,7 +16,6 @@ 'use strict'; var assert = require('assert'); var nock = require('nock'); -var path = require('path'); var proxyquire = require('proxyquire'); describe('common/metadata', function() { @@ -62,7 +61,7 @@ describe('common/metadata', function() { done(); }); }); - + it('should be able handle 500\'s from the service', function(done) { var scope = nock('http://metadata.google.internal') @@ -83,11 +82,11 @@ describe('common/metadata', function() { it('should accept an optional headers parameter', function(done) { var scope = nock('http://metadata.google.internal', { - reqheaders: {'Flux': 'Capacitor'} + reqheaders: { Flux: 'Capacitor' } }) .get('/computeMetadata/v1/project/project-id') .reply(200, 'a-stub-project-id'); - metadata.getProjectId({'Flux': 'Capacitor'}, function(err, project) { + metadata.getProjectId({ Flux: 'Capacitor' }, function(err, project) { assert.ok(!err); assert.strictEqual(project, 'a-stub-project-id'); scope.done(); @@ -95,14 +94,14 @@ describe('common/metadata', function() { }); }); - it('Should callback with ENOTFOUND', function (done) { + it('should callback with ENOTFOUND', function(done) { var oldEnv = process.env.GCLOUD_PROJECT; process.env.GCLOUD_PROJECT = './this-should-not-exist.json'; var scope = nock('http://metadata.google.internal') .get('/computeMetadata/v1/project/project-id') .once() - .replyWithError({'message': 'Not Found', code: 'ENOTFOUND'}); - metadata.getProjectId(function (e, result) { + .replyWithError({ message: 'Not Found', code: 'ENOTFOUND' }); + metadata.getProjectId(function(e, result) { assert.ok(e instanceof Error, 'e should be an instance of Error'); assert.deepEqual(result, null); process.env.GCLOUD_PROJECT = oldEnv; @@ -114,14 +113,14 @@ describe('common/metadata', function() { describe('getInstanceId - valid cases', function() { var STUB_ID = 'a-stub-instance-id'; - it( - 'Should be able to get the instance id without additional headers supplied', - function (done) { + it('should be able to get the instance id without additional headers ' + + 'supplied', + function(done) { var mock = nock('http://metadata.google.internal/computeMetadata/v1') .get('/instance/id') .once() .reply(200, STUB_ID); - metadata.getInstanceId(function (err, id) { + metadata.getInstanceId(function(err, id) { assert.deepEqual(err, null, 'Error should be null'); assert.deepEqual(STUB_ID, id, 'The id should be the stub id'); mock.done(); @@ -129,15 +128,14 @@ describe('common/metadata', function() { }); } ); - it( - 'Should be able to get the instance id with additional headers supplied', - function (done) { + it('should be able to get the instance id with additional headers supplied', + function(done) { var mock = nock('http://metadata.google.internal/computeMetadata/v1', {reqHeaders: {'x-custom-header': 'true'}}) .get('/instance/id') .once() .reply(200, STUB_ID); - metadata.getInstanceId({'x-custom-header': 'true'}, function (err, id) { + metadata.getInstanceId({'x-custom-header': 'true'}, function(err, id) { assert.deepEqual(err, null, 'Error should be null'); assert.deepEqual(STUB_ID, id, 'The id should be the stub id'); mock.done(); @@ -149,14 +147,13 @@ describe('common/metadata', function() { describe('getHostname - valid cases', function() { var STUB_HOSTNAME = 'a-stub-hostname'; - it( - 'Should be able to get the hostname without additional headers supplied', - function (done) { + it('should be able to get the hostname without additional headers supplied', + function(done) { var mock = nock('http://metadata.google.internal/computeMetadata/v1') .get('/instance/hostname') .once() .reply(200, STUB_HOSTNAME); - metadata.getHostname(function (err, id) { + metadata.getHostname(function(err, id) { assert.deepEqual(err, null, 'Error should be null'); assert.deepEqual(STUB_HOSTNAME, id, 'The hostname should be the stub hostname'); @@ -165,15 +162,14 @@ describe('common/metadata', function() { }); } ); - it( - 'Should be able to get the hostname with additional headers supplied', - function (done) { + it('should be able to get the hostname with additional headers supplied', + function(done) { var mock = nock('http://metadata.google.internal/computeMetadata/v1', {reqHeaders: {'x-custom-header': 'true'}}) .get('/instance/hostname') .once() .reply(200, STUB_HOSTNAME); - metadata.getHostname({'x-custom-header': 'true'}, function (err, id) { + metadata.getHostname({'x-custom-header': 'true'}, function(err, id) { assert.deepEqual(err, null, 'Error should be null'); assert.deepEqual(STUB_HOSTNAME, id, 'The hostname should be the stub hostname'); diff --git a/packages/common/test/paginator.js b/packages/common/test/paginator.js index 33455b53c887..0c5e32258982 100644 --- a/packages/common/test/paginator.js +++ b/packages/common/test/paginator.js @@ -49,7 +49,7 @@ function override(name, object) { return cachedObject[methodName].apply(this, args); }; - object[methodName].unoverride_ = function () { + object[methodName].unoverride_ = function() { object[methodName] = cachedObject[methodName]; }; }); @@ -57,14 +57,14 @@ function override(name, object) { // Reverses the override function. function unoverride(object) { - Object.keys(object).forEach(function (methodName) { + Object.keys(object).forEach(function(methodName) { if (object[methodName].unoverride_) { object[methodName].unoverride_(); } }); } -// Resets all overridden functions. +// Resets all overridden functions. function resetOverrides() { overrides = Object.keys(overrides).reduce(function(acc, name) { acc[name] = {}; diff --git a/packages/common/test/util.js b/packages/common/test/util.js index 05def24d4186..828a7b04d712 100644 --- a/packages/common/test/util.js +++ b/packages/common/test/util.js @@ -98,11 +98,11 @@ describe('common/util', function() { after(function() { // Set each function in util to its original value - Object.keys(util).forEach(function (utilMethod) { + Object.keys(util).forEach(function(utilMethod) { if (util[utilMethod].unoverride_) { util[utilMethod].unoverride_(); } - }) + }); }); it('should have set correct defaults on Request', function() {