From 0fdd03ddfce08b1f57803864bf3dd24aa77e2bd8 Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Mon, 16 Sep 2019 11:53:51 -0300 Subject: [PATCH 1/7] refactor: remove functions_concepts_error_object --- functions/concepts/index.js | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/functions/concepts/index.js b/functions/concepts/index.js index b4d8dd0dbf..d51ca73285 100644 --- a/functions/concepts/index.js +++ b/functions/concepts/index.js @@ -15,29 +15,6 @@ 'use strict'; -/** - * HTTP Cloud Function that demonstrates - * how to catch errors of different types. - * - * @param {Object} req Cloud Function request context. - * @param {Object} req.body Cloud Function request context body. - * @param {String} req.body.topic The Cloud Pub/Sub topic to publish to. - * @param {Object} res Cloud Function response context. - */ -exports.errorTypes = (req, res) => { - // [START functions_concepts_error_object] - try { - // Throw an Error object (to simulate a GCP API failure) - throw new Error('Error object!'); - } catch (err) { - // err is already an Error object - console.error(err); - } - // [END functions_concepts_error_object] - - res.end(); -}; - // [START functions_concepts_stateless] // Global variable, but only shared within function instance. let count = 0; From b6c6a05b86c04e73daa3f2bc6e22e9d93ce47731 Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Wed, 18 Sep 2019 12:07:38 -0300 Subject: [PATCH 2/7] test: Removes unused sample test --- functions/concepts/test/index.test.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/functions/concepts/test/index.test.js b/functions/concepts/test/index.test.js index 13b709463a..569be3ba18 100644 --- a/functions/concepts/test/index.test.js +++ b/functions/concepts/test/index.test.js @@ -15,21 +15,7 @@ 'use strict'; -const sinon = require('sinon'); -const assert = require('assert'); const tools = require('@google-cloud/nodejs-repo-tools'); -const sample = require('../'); - beforeEach(tools.stubConsole); afterEach(tools.restoreConsole); - -it('should demonstrate error type behavior', () => { - const objError = new Error('Error object!'); - - const req = {body: {throwAsString: true}}; - const res = {end: sinon.stub()}; - - sample.errorTypes(req, res); - assert.deepStrictEqual(console.error.getCall(0).args, [objError]); -}); From b355b2ab022fa13a0ac643c731e46140c4c89e48 Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Fri, 20 Sep 2019 17:22:45 -0300 Subject: [PATCH 3/7] feat: Add more samples --- cloud-sql/mysql/mysql/server.js | 2 +- cloud-sql/postgres/knex/server.js | 2 +- functions/billing/index.js | 2 +- functions/scheduleinstance/index.js | 4 ++-- functions/tokenservice/functions/index.js | 5 ++--- iot/http_example/cloudiot_http_example.js | 4 ++-- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cloud-sql/mysql/mysql/server.js b/cloud-sql/mysql/mysql/server.js index 4681af584b..774a0f5976 100644 --- a/cloud-sql/mysql/mysql/server.js +++ b/cloud-sql/mysql/mysql/server.js @@ -156,7 +156,7 @@ app.post('/', async (req, res) => { res .status(200) - .send('Successfully voted for ' + team + ' at ' + timestamp) + .send(`Successfully voted for ${team} at ${timestamp}`) .end(); }); diff --git a/cloud-sql/postgres/knex/server.js b/cloud-sql/postgres/knex/server.js index c58d08e48c..e99361e110 100644 --- a/cloud-sql/postgres/knex/server.js +++ b/cloud-sql/postgres/knex/server.js @@ -212,7 +212,7 @@ app.post('/', async (req, res) => { try { await insertVote(knex, vote); } catch (err) { - logger.error('Error while attempting to submit vote:' + err); + logger.error(`Error while attempting to submit vote:${err}`); res .status(500) .send('Unable to cast vote; see logs for more details.') diff --git a/functions/billing/index.js b/functions/billing/index.js index 9be57c4ae3..4cdc28ecc8 100644 --- a/functions/billing/index.js +++ b/functions/billing/index.js @@ -187,7 +187,7 @@ const _stopInstances = async (projectId, zone, instanceNames) => { instance: instanceName, }) .then(res => { - console.log('Instance stopped successfully: ' + instanceName); + console.log(`Instance stopped successfully: ${instanceName}`); return res.data; }); }) diff --git a/functions/scheduleinstance/index.js b/functions/scheduleinstance/index.js index f30e567f00..03e8470b2e 100644 --- a/functions/scheduleinstance/index.js +++ b/functions/scheduleinstance/index.js @@ -51,7 +51,7 @@ exports.startInstancePubSub = (event, context, callback) => { }) .then(() => { // Operation complete. Instance successfully started. - const message = 'Successfully started instance ' + instance.name; + const message = `Successfully started instance ${instance.name}`; console.log(message); callback(null, message); }) @@ -101,7 +101,7 @@ exports.stopInstancePubSub = (event, context, callback) => { }) .then(() => { // Operation complete. Instance successfully stopped. - const message = 'Successfully stopped instance ' + instance.name; + const message = `Successfully stopped instance ${instance.name}`; console.log(message); callback(null, message); }) diff --git a/functions/tokenservice/functions/index.js b/functions/tokenservice/functions/index.js index cd9feff53f..549f105854 100644 --- a/functions/tokenservice/functions/index.js +++ b/functions/tokenservice/functions/index.js @@ -49,8 +49,7 @@ function generateAccessToken( method: 'POST', headers: { // Set Service Account Credentials - Authorization: - serviceAccountTokenType + ' ' + serviceAccountAccessToken, + Authorization: `${serviceAccountTokenType} ${serviceAccountAccessToken}`, }, }; @@ -120,7 +119,7 @@ function retrieveCredentials(context) { }); get_req.on('error', e => { //console.log('Error retrieving credentials', e.message); - return 'Error retrieving token' + e.message; + return `Error retrieving token${e.message}`; }); get_req.end(); }); diff --git a/iot/http_example/cloudiot_http_example.js b/iot/http_example/cloudiot_http_example.js index de2d4103f2..0dbba3d2ba 100644 --- a/iot/http_example/cloudiot_http_example.js +++ b/iot/http_example/cloudiot_http_example.js @@ -174,7 +174,7 @@ function publishAsync(authToken, messageCount, numMessages) { if (error) { console.error('Received error: ', error); } else if (response.body.error) { - console.error('Received error: ' + JSON.stringify(response.body.error)); + console.error(`Received error: ${JSON.stringify(response.body.error)}`); } else { console.log('Message sent.'); } @@ -205,7 +205,7 @@ function getConfig(authToken, version) { console.log(`Getting config from URL: ${urlBase}`); const options = { - url: urlBase + '/config?local_version=' + version, + url: `${urlBase}/config?local_version=${version}`, headers: { authorization: `Bearer ${authToken}`, 'content-type': 'application/json', From c86ab955b4d5ec7e58d743ee3483e34928f40fc5 Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Mon, 23 Sep 2019 09:35:13 -0300 Subject: [PATCH 4/7] refactor: rm functions/concepts/test/index.test.js --- functions/concepts/test/index.test.js | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 functions/concepts/test/index.test.js diff --git a/functions/concepts/test/index.test.js b/functions/concepts/test/index.test.js deleted file mode 100644 index 569be3ba18..0000000000 --- a/functions/concepts/test/index.test.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2018, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const tools = require('@google-cloud/nodejs-repo-tools'); - -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); From b2ea68270ac9c2baa9417a5c5d2133ed3b55b751 Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Mon, 23 Sep 2019 09:57:16 -0300 Subject: [PATCH 5/7] revert template string changes --- cloud-sql/mysql/mysql/server.js | 2 +- cloud-sql/postgres/knex/server.js | 2 +- functions/billing/index.js | 2 +- functions/scheduleinstance/index.js | 4 ++-- functions/tokenservice/functions/index.js | 5 +++-- iot/http_example/cloudiot_http_example.js | 4 ++-- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cloud-sql/mysql/mysql/server.js b/cloud-sql/mysql/mysql/server.js index 774a0f5976..4681af584b 100644 --- a/cloud-sql/mysql/mysql/server.js +++ b/cloud-sql/mysql/mysql/server.js @@ -156,7 +156,7 @@ app.post('/', async (req, res) => { res .status(200) - .send(`Successfully voted for ${team} at ${timestamp}`) + .send('Successfully voted for ' + team + ' at ' + timestamp) .end(); }); diff --git a/cloud-sql/postgres/knex/server.js b/cloud-sql/postgres/knex/server.js index e99361e110..c58d08e48c 100644 --- a/cloud-sql/postgres/knex/server.js +++ b/cloud-sql/postgres/knex/server.js @@ -212,7 +212,7 @@ app.post('/', async (req, res) => { try { await insertVote(knex, vote); } catch (err) { - logger.error(`Error while attempting to submit vote:${err}`); + logger.error('Error while attempting to submit vote:' + err); res .status(500) .send('Unable to cast vote; see logs for more details.') diff --git a/functions/billing/index.js b/functions/billing/index.js index 4cdc28ecc8..9be57c4ae3 100644 --- a/functions/billing/index.js +++ b/functions/billing/index.js @@ -187,7 +187,7 @@ const _stopInstances = async (projectId, zone, instanceNames) => { instance: instanceName, }) .then(res => { - console.log(`Instance stopped successfully: ${instanceName}`); + console.log('Instance stopped successfully: ' + instanceName); return res.data; }); }) diff --git a/functions/scheduleinstance/index.js b/functions/scheduleinstance/index.js index 03e8470b2e..f30e567f00 100644 --- a/functions/scheduleinstance/index.js +++ b/functions/scheduleinstance/index.js @@ -51,7 +51,7 @@ exports.startInstancePubSub = (event, context, callback) => { }) .then(() => { // Operation complete. Instance successfully started. - const message = `Successfully started instance ${instance.name}`; + const message = 'Successfully started instance ' + instance.name; console.log(message); callback(null, message); }) @@ -101,7 +101,7 @@ exports.stopInstancePubSub = (event, context, callback) => { }) .then(() => { // Operation complete. Instance successfully stopped. - const message = `Successfully stopped instance ${instance.name}`; + const message = 'Successfully stopped instance ' + instance.name; console.log(message); callback(null, message); }) diff --git a/functions/tokenservice/functions/index.js b/functions/tokenservice/functions/index.js index 549f105854..cd9feff53f 100644 --- a/functions/tokenservice/functions/index.js +++ b/functions/tokenservice/functions/index.js @@ -49,7 +49,8 @@ function generateAccessToken( method: 'POST', headers: { // Set Service Account Credentials - Authorization: `${serviceAccountTokenType} ${serviceAccountAccessToken}`, + Authorization: + serviceAccountTokenType + ' ' + serviceAccountAccessToken, }, }; @@ -119,7 +120,7 @@ function retrieveCredentials(context) { }); get_req.on('error', e => { //console.log('Error retrieving credentials', e.message); - return `Error retrieving token${e.message}`; + return 'Error retrieving token' + e.message; }); get_req.end(); }); diff --git a/iot/http_example/cloudiot_http_example.js b/iot/http_example/cloudiot_http_example.js index 0dbba3d2ba..de2d4103f2 100644 --- a/iot/http_example/cloudiot_http_example.js +++ b/iot/http_example/cloudiot_http_example.js @@ -174,7 +174,7 @@ function publishAsync(authToken, messageCount, numMessages) { if (error) { console.error('Received error: ', error); } else if (response.body.error) { - console.error(`Received error: ${JSON.stringify(response.body.error)}`); + console.error('Received error: ' + JSON.stringify(response.body.error)); } else { console.log('Message sent.'); } @@ -205,7 +205,7 @@ function getConfig(authToken, version) { console.log(`Getting config from URL: ${urlBase}`); const options = { - url: `${urlBase}/config?local_version=${version}`, + url: urlBase + '/config?local_version=' + version, headers: { authorization: `Bearer ${authToken}`, 'content-type': 'application/json', From 57875141cb2b70d68ee29a5aa311a6dd2952fbd8 Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Fri, 11 Oct 2019 11:35:25 -0300 Subject: [PATCH 6/7] fix: delete test file --- functions/concepts/test/index.test.js | 37 --------------------------- 1 file changed, 37 deletions(-) delete mode 100644 functions/concepts/test/index.test.js diff --git a/functions/concepts/test/index.test.js b/functions/concepts/test/index.test.js deleted file mode 100644 index 8e573c2eb1..0000000000 --- a/functions/concepts/test/index.test.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2018, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const sinon = require('sinon'); -const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); - -const sample = require('../'); - -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); - -describe('functions_concepts_error_object', () => { - it('should demonstrate error type behavior', () => { - const objError = new Error('Error object!'); - - const req = {body: {throwAsString: true}}; - const res = {end: sinon.stub()}; - - sample.errorTypes(req, res); - assert.deepStrictEqual(console.error.getCall(0).args, [objError]); - }); -}); From ad36354f0a1295b6ad594d6f9b48ee19a0bf7aa3 Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Tue, 22 Oct 2019 10:20:39 -0500 Subject: [PATCH 7/7] Delete concepts.cfg --- .kokoro/functions/concepts.cfg | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 .kokoro/functions/concepts.cfg diff --git a/.kokoro/functions/concepts.cfg b/.kokoro/functions/concepts.cfg deleted file mode 100644 index bc7481bf55..0000000000 --- a/.kokoro/functions/concepts.cfg +++ /dev/null @@ -1,13 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Set the folder in which the tests are run -env_vars: { - key: "PROJECT" - value: "functions/concepts" -} - -# Tell the trampoline which build file to use. -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/nodejs-docs-samples/.kokoro/build.sh" -}