From a90ad7a449c80dbbe28b9c75ff01807d5630bf3b Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Fri, 5 Jan 2018 16:34:55 -0800 Subject: [PATCH 01/21] Add sample HTTP system test --- .../test/sample.system.http.test.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 functions/helloworld/test/sample.system.http.test.js diff --git a/functions/helloworld/test/sample.system.http.test.js b/functions/helloworld/test/sample.system.http.test.js new file mode 100644 index 0000000000..e76400411d --- /dev/null +++ b/functions/helloworld/test/sample.system.http.test.js @@ -0,0 +1,41 @@ +/** + * 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. + */ + +// [START functions_sample_http_test] +const test = require(`ava`); +const supertest = require(`supertest`); +const BASE_URL = process.env.BASE_URL; + +test.cb(`helloHttp: should print a name`, (t) => { + supertest(BASE_URL) + .post(`/helloHttp`) + .send({ name: 'John' }) + .expect(200) + .expect((response) => { + t.is(response.text, 'Hello John!'); + }) + .end(t.end); +}); + +test.cb(`helloHttp: should print hello world`, (t) => { + supertest(BASE_URL) + .get(`/helloHttp`) + .expect(200) + .expect((response) => { + t.is(response.text, `Hello World!`); + }) + .end(t.end); +}); +// [END functions_sample_http_test] From 38feeb2ac565a42a617aa5cd2b32ba7073e549f2 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Mon, 8 Jan 2018 14:13:12 -0800 Subject: [PATCH 02/21] Add sample pub/sub system test --- .../test/sample.system.pubsub.test.js | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 functions/helloworld/test/sample.system.pubsub.test.js diff --git a/functions/helloworld/test/sample.system.pubsub.test.js b/functions/helloworld/test/sample.system.pubsub.test.js new file mode 100644 index 0000000000..259e3adc57 --- /dev/null +++ b/functions/helloworld/test/sample.system.pubsub.test.js @@ -0,0 +1,47 @@ +/** + * 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. + */ + +// [START functions_sample_pubsub_test] +const childProcess = require(`child_process`); +const test = require(`ava`); +const uuid = require(`uuid`); + +test(`helloPubSub: should print a name`, async (t) => { + t.plan(1); + const startTime = new Date(Date.now()).toISOString(); + const name = uuid.v4(); + + // Mock Pub/Sub call, as the emulator doesn't listen to Pub/Sub topics + const encodedName = Buffer.from(name).toString(`base64`); + const data = JSON.stringify({ data: encodedName }); + childProcess.execSync(`functions call helloPubSub --data '${data}'`); + + // Check the emulator's logs + const logs = childProcess.execSync(`functions logs read helloPubSub --start-time ${startTime}`).toString(); + t.true(logs.includes(`Hello, ${name}!`)); +}); + +test(`helloPubSub: should print hello world`, async (t) => { + t.plan(1); + const startTime = new Date(Date.now()).toISOString(); + + // Mock Pub/Sub call, as the emulator doesn't listen to Pub/Sub topics + childProcess.execSync(`functions call helloPubSub --data {}`); + + // Check the emulator's logs + const logs = childProcess.execSync(`functions logs read helloPubSub --start-time ${startTime}`).toString(); + t.true(logs.includes(`Hello, World!`)); +}); +// [END functions_sample_pubsub_test] From 9e7462546c38bf19f25bbc516b1fce4ded0f1365 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Mon, 8 Jan 2018 14:14:21 -0800 Subject: [PATCH 03/21] Fix style nits --- functions/helloworld/test/sample.system.http.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/functions/helloworld/test/sample.system.http.test.js b/functions/helloworld/test/sample.system.http.test.js index e76400411d..2d9fbf2c93 100644 --- a/functions/helloworld/test/sample.system.http.test.js +++ b/functions/helloworld/test/sample.system.http.test.js @@ -15,11 +15,11 @@ // [START functions_sample_http_test] const test = require(`ava`); -const supertest = require(`supertest`); -const BASE_URL = process.env.BASE_URL; +const Supertest = require(`supertest`); +const supertest = Supertest(process.env.BASE_URL); test.cb(`helloHttp: should print a name`, (t) => { - supertest(BASE_URL) + supertest .post(`/helloHttp`) .send({ name: 'John' }) .expect(200) @@ -30,7 +30,7 @@ test.cb(`helloHttp: should print a name`, (t) => { }); test.cb(`helloHttp: should print hello world`, (t) => { - supertest(BASE_URL) + supertest .get(`/helloHttp`) .expect(200) .expect((response) => { From 48395654e2216e07cab91e5f24d2cdeb61037f84 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Mon, 8 Jan 2018 17:31:54 -0800 Subject: [PATCH 04/21] Rename region tags to prevent conflicts --- functions/helloworld/test/sample.system.http.test.js | 4 ++-- functions/helloworld/test/sample.system.pubsub.test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/functions/helloworld/test/sample.system.http.test.js b/functions/helloworld/test/sample.system.http.test.js index 2d9fbf2c93..b4a750b937 100644 --- a/functions/helloworld/test/sample.system.http.test.js +++ b/functions/helloworld/test/sample.system.http.test.js @@ -13,7 +13,7 @@ * limitations under the License. */ -// [START functions_sample_http_test] +// [START functions_http_system_test] const test = require(`ava`); const Supertest = require(`supertest`); const supertest = Supertest(process.env.BASE_URL); @@ -38,4 +38,4 @@ test.cb(`helloHttp: should print hello world`, (t) => { }) .end(t.end); }); -// [END functions_sample_http_test] +// [END functions_http_system_test] diff --git a/functions/helloworld/test/sample.system.pubsub.test.js b/functions/helloworld/test/sample.system.pubsub.test.js index 259e3adc57..938b454397 100644 --- a/functions/helloworld/test/sample.system.pubsub.test.js +++ b/functions/helloworld/test/sample.system.pubsub.test.js @@ -13,7 +13,7 @@ * limitations under the License. */ -// [START functions_sample_pubsub_test] +// [START functions_pubsub_system_test] const childProcess = require(`child_process`); const test = require(`ava`); const uuid = require(`uuid`); @@ -44,4 +44,4 @@ test(`helloPubSub: should print hello world`, async (t) => { const logs = childProcess.execSync(`functions logs read helloPubSub --start-time ${startTime}`).toString(); t.true(logs.includes(`Hello, World!`)); }); -// [END functions_sample_pubsub_test] +// [END functions_pubsub_system_test] From 2fa228cbb507811cbe5fe5240dc1ce822fc8245a Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Mon, 8 Jan 2018 17:42:26 -0800 Subject: [PATCH 05/21] Add sample HTTP unit test --- .../helloworld/test/sample.unit.http.test.js | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 functions/helloworld/test/sample.unit.http.test.js diff --git a/functions/helloworld/test/sample.unit.http.test.js b/functions/helloworld/test/sample.unit.http.test.js new file mode 100644 index 0000000000..e08d1d6ec8 --- /dev/null +++ b/functions/helloworld/test/sample.unit.http.test.js @@ -0,0 +1,55 @@ +/** + * 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. + */ + +// [START functions_http_unit_test] +const test = require(`ava`); +const sinon = require(`sinon`); +const uuid = require(`uuid`); + +const helloHttp = require(`..`).helloHttp; + +test(`helloHttp: should print a name`, t => { + // Initialize mocks + const name = uuid.v4(); + const req = { + body: { + name: name + } + }; + const res = { send: sinon.stub() }; + + // Call tested function + helloHttp(req, res); + + // Verify behavior of tested function + t.true(res.send.calledOnce); + t.deepEqual(res.send.firstCall.args, [`Hello ${name}!`]); +}); + +test(`helloHttp: should print hello world`, t => { + // Initialize mocks + const req = { + body: {} + }; + const res = { send: sinon.stub() }; + + // Call tested function + helloHttp(req, res); + + // Verify behavior of tested function + t.true(res.send.calledOnce); + t.deepEqual(res.send.firstCall.args, [`Hello World!`]); +}); +// [END functions_http_unit_test] From 4afcaa6fcb6381e4de711b131a909eb63a3af0a9 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Mon, 8 Jan 2018 18:40:39 -0800 Subject: [PATCH 06/21] Add Pub/Sub unit test --- .../test/sample.unit.pubsub.test.js | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 functions/helloworld/test/sample.unit.pubsub.test.js diff --git a/functions/helloworld/test/sample.unit.pubsub.test.js b/functions/helloworld/test/sample.unit.pubsub.test.js new file mode 100644 index 0000000000..85910bad07 --- /dev/null +++ b/functions/helloworld/test/sample.unit.pubsub.test.js @@ -0,0 +1,56 @@ +/** + * 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. + */ + +// [START functions_pubsub_unit_test] +const test = require(`ava`); +const uuid = require(`uuid`); +const sinon = require(`sinon`); + +const helloPubSub = require(`..`).helloPubSub; +const consoleLog = sinon.stub(console, 'log'); + +test.cb(`helloPubSub: should print a name`, t => { + t.plan(1); + + // Initialize mocks + const name = uuid.v4(); + const event = { + data: { + data: Buffer.from(name).toString(`base64`) + } + }; + + // Call tested function and verify its behavior + helloPubSub(event, () => { + t.true(consoleLog.calledWith(`Hello, ${name}!`)); + t.end(); + }); +}); + +test.cb(`helloPubSub: should print hello world`, t => { + t.plan(1); + + // Initialize mocks + const event = { + data: {} + }; + + // Call tested function and verify its behavior + helloPubSub(event, () => { + t.true(consoleLog.calledWith(`Hello, World!`)); + t.end(); + }); +}); +// [END functions_pubsub_unit_test] From f7cc86a71cd0fe7e6b636d87daecc8ec61d5d7ed Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Tue, 9 Jan 2018 12:09:29 -0800 Subject: [PATCH 07/21] Add storage unit test sample --- .../test/sample.unit.storage.test.js | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 functions/helloworld/test/sample.unit.storage.test.js diff --git a/functions/helloworld/test/sample.unit.storage.test.js b/functions/helloworld/test/sample.unit.storage.test.js new file mode 100644 index 0000000000..a13a1b5250 --- /dev/null +++ b/functions/helloworld/test/sample.unit.storage.test.js @@ -0,0 +1,83 @@ +/** + * 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. + */ + +// [START functions_storage_unit_test] +const test = require(`ava`); +const uuid = require(`uuid`); +const sinon = require(`sinon`); + +const helloGCS = require(`..`).helloGCS; +const consoleLog = sinon.stub(console, 'log'); + +test.cb(`helloGCS: should print uploaded message`, t => { + t.plan(1); + + // Initialize mocks + const filename = uuid.v4(); + const event = { + data: { + name: filename, + resourceState: 'exists', + metageneration: '1' + } + }; + + // Call tested function and verify its behavior + helloGCS(event, () => { + t.true(consoleLog.calledWith(`File ${filename} uploaded.`)); + t.end(); + }); +}); + +test.cb(`helloGCS: should print metadata updated message`, t => { + t.plan(1); + + // Initialize mocks + const filename = uuid.v4(); + const event = { + data: { + name: filename, + resourceState: 'exists', + metageneration: '2' + } + }; + + // Call tested function and verify its behavior + helloGCS(event, () => { + t.true(consoleLog.calledWith(`File ${filename} metadata updated.`)); + t.end(); + }); +}); + +test.cb(`helloGCS: should print deleted message`, t => { + t.plan(1); + + // Initialize mocks + const filename = uuid.v4(); + const event = { + data: { + name: filename, + resourceState: 'not_exists', + metageneration: '3' + } + }; + + // Call tested function and verify its behavior + helloGCS(event, () => { + t.true(consoleLog.calledWith(`File ${filename} deleted.`)); + t.end(); + }); +}); +// [END functions_storage_unit_test] From ca67f77d67187391979cbe4f18238b993ce3e67e Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Tue, 9 Jan 2018 14:11:26 -0800 Subject: [PATCH 08/21] Add storage system test sample --- .../test/sample.system.storage.test.js | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 functions/helloworld/test/sample.system.storage.test.js diff --git a/functions/helloworld/test/sample.system.storage.test.js b/functions/helloworld/test/sample.system.storage.test.js new file mode 100644 index 0000000000..2152f6decb --- /dev/null +++ b/functions/helloworld/test/sample.system.storage.test.js @@ -0,0 +1,77 @@ +/** + * 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. + */ + +// [START functions_storage_system_test] +const childProcess = require(`child_process`); +const test = require(`ava`); +const uuid = require(`uuid`); + +test(`helloGCS: should print uploaded message`, async (t) => { + t.plan(1); + const startTime = new Date(Date.now()).toISOString(); + const filename = uuid.v4(); // Use a unique filename to avoid conflicts + + // Mock GCS call, as the emulator doesn't listen to GCS buckets + const data = JSON.stringify({ + name: filename, + resourceState: 'exists', + metageneration: '1' + }); + + childProcess.execSync(`functions call helloGCS --data '${data}'`); + + // Check the emulator's logs + const logs = childProcess.execSync(`functions logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${filename} uploaded.`)); +}); + +test(`helloGCS: should print metadata updated message`, async (t) => { + t.plan(1); + const startTime = new Date(Date.now()).toISOString(); + const filename = uuid.v4(); // Use a unique filename to avoid conflicts + + // Mock GCS call, as the emulator doesn't listen to GCS buckets + const data = JSON.stringify({ + name: filename, + resourceState: 'exists', + metageneration: '2' + }); + + childProcess.execSync(`functions call helloGCS --data '${data}'`); + + // Check the emulator's logs + const logs = childProcess.execSync(`functions logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${filename} metadata updated.`)); +}); + +test(`helloGCS: should print deleted message`, async (t) => { + t.plan(1); + const startTime = new Date(Date.now()).toISOString(); + const filename = uuid.v4(); // Use a unique filename to avoid conflicts + + // Mock GCS call, as the emulator doesn't listen to GCS buckets + const data = JSON.stringify({ + name: filename, + resourceState: 'not_exists', + metageneration: '3' + }); + + childProcess.execSync(`functions call helloGCS --data '${data}'`); + + // Check the emulator's logs + const logs = childProcess.execSync(`functions logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${filename} deleted.`)); +}); +// [END functions_storage_system_test] From 474f5db404dd2e3a441be3bef5e132f07cd1b1cb Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Tue, 9 Jan 2018 17:22:24 -0800 Subject: [PATCH 09/21] Add storage integration test sample --- .../test/sample.integration.storage.test.js | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 functions/helloworld/test/sample.integration.storage.test.js diff --git a/functions/helloworld/test/sample.integration.storage.test.js b/functions/helloworld/test/sample.integration.storage.test.js new file mode 100644 index 0000000000..5957bd34dd --- /dev/null +++ b/functions/helloworld/test/sample.integration.storage.test.js @@ -0,0 +1,78 @@ +/** + * 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. + */ + +const Storage = require(`@google-cloud/storage`); +const storage = Storage(); +const uuid = require(`uuid`); +const test = require(`ava`); +const path = require(`path`); +const childProcess = require(`child_process`); +const localFileName = `test.txt`; + +// Use unique GCS filename to avoid conflicts between concurrent test runs +const gcsFileName = `test-${uuid.v4()}.txt`; + +const bucketName = process.env.BUCKET_NAME; +const bucket = storage.bucket(bucketName); +const baseCmd = `gcloud beta functions`; + +test.serial(`helloGCS: should print uploaded message`, async (t) => { + t.plan(1); + const startTime = new Date(Date.now()).toISOString(); + + // Upload file + const filepath = path.join(__dirname, localFileName); + await bucket.upload(filepath, { + destination: gcsFileName + }); + + // Wait for consistency + await new Promise(resolve => setTimeout(resolve, 15000)); + + // Check logs + const logs = childProcess.execSync(`${baseCmd} logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${gcsFileName} uploaded`)); +}); + +test.serial(`helloGCS: should print metadata updated message`, async (t) => { + t.plan(1); + const startTime = new Date(Date.now()).toISOString(); + + // Update file metadata + const file = bucket.file(gcsFileName); + await file.setMetadata(gcsFileName, { foo: `bar` }); + + // Wait for consistency + await new Promise(resolve => setTimeout(resolve, 15000)); + + // Check logs + const logs = childProcess.execSync(`${baseCmd} logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${gcsFileName} metadata updated`)); +}); + +test.serial(`helloGCS: should print deleted message`, async (t) => { + t.plan(1); + const startTime = new Date(Date.now()).toISOString(); + + // Delete file + bucket.deleteFiles(); + + // Wait for consistency + await new Promise(resolve => setTimeout(resolve, 15000)); + + // Check logs + const logs = childProcess.execSync(`${baseCmd} logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${gcsFileName} deleted`)); +}); From ef07e9bfcedafa9869af945e400612f32cac1c9f Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 10 Jan 2018 15:15:35 -0800 Subject: [PATCH 10/21] Add PubSub integration test sample --- .../test/sample.integration.pubsub.test.js | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 functions/helloworld/test/sample.integration.pubsub.test.js diff --git a/functions/helloworld/test/sample.integration.pubsub.test.js b/functions/helloworld/test/sample.integration.pubsub.test.js new file mode 100644 index 0000000000..b38ba2f9d9 --- /dev/null +++ b/functions/helloworld/test/sample.integration.pubsub.test.js @@ -0,0 +1,60 @@ +/** + * 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. + */ + +// [START functions_pubsub_integration_test] +const childProcess = require(`child_process`); +const test = require(`ava`); +const uuid = require(`uuid`); +const Pubsub = require(`@google-cloud/pubsub`); +const pubsub = Pubsub(); + +const topicName = process.env.FUNCTIONS_TOPIC; +const baseCmd = `gcloud beta functions`; + +test(`helloPubSub: should print a name`, async (t) => { + t.plan(1); + const startTime = new Date(Date.now()).toISOString(); + const name = uuid.v4(); + + // Publish to pub/sub topic + const topic = pubsub.topic(topicName); + const publisher = topic.publisher(); + await publisher.publish(Buffer.from(name)); + + // Wait for logs to become consistent + await new Promise(resolve => setTimeout(resolve, 15000)); + + // Check logs after a delay + const logs = childProcess.execSync(`${baseCmd} logs read helloPubSub --start-time ${startTime}`).toString(); + t.true(logs.includes(`Hello, ${name}!`)); +}); + +test(`helloPubSub: should print hello world`, async (t) => { + t.plan(1); + const startTime = new Date(Date.now()).toISOString(); + + // Publish to pub/sub topic + const topic = pubsub.topic(topicName); + const publisher = topic.publisher(); + await publisher.publish(Buffer.from(''), { a: 'b' }); + + // Wait for logs to become consistent + await new Promise(resolve => setTimeout(resolve, 15000)); + + // Check logs after a delay + const logs = childProcess.execSync(`${baseCmd} logs read helloPubSub --start-time ${startTime}`).toString(); + t.true(logs.includes('Hello, World!')); +}); +// [END functions_pubsub_integration_test] From f79f34b580a505b8c8e07dc55461780c5d3ea11f Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 17 Jan 2018 13:16:19 -0800 Subject: [PATCH 11/21] Swap integration + system tests to address Marek's comments --- .../test/sample.integration.pubsub.test.js | 39 +++------ .../test/sample.integration.storage.test.js | 79 +++++++++---------- .../test/sample.system.pubsub.test.js | 39 ++++++--- .../test/sample.system.storage.test.js | 79 ++++++++++--------- 4 files changed, 118 insertions(+), 118 deletions(-) diff --git a/functions/helloworld/test/sample.integration.pubsub.test.js b/functions/helloworld/test/sample.integration.pubsub.test.js index b38ba2f9d9..938b454397 100644 --- a/functions/helloworld/test/sample.integration.pubsub.test.js +++ b/functions/helloworld/test/sample.integration.pubsub.test.js @@ -13,31 +13,23 @@ * limitations under the License. */ -// [START functions_pubsub_integration_test] +// [START functions_pubsub_system_test] const childProcess = require(`child_process`); const test = require(`ava`); const uuid = require(`uuid`); -const Pubsub = require(`@google-cloud/pubsub`); -const pubsub = Pubsub(); - -const topicName = process.env.FUNCTIONS_TOPIC; -const baseCmd = `gcloud beta functions`; test(`helloPubSub: should print a name`, async (t) => { t.plan(1); const startTime = new Date(Date.now()).toISOString(); const name = uuid.v4(); - // Publish to pub/sub topic - const topic = pubsub.topic(topicName); - const publisher = topic.publisher(); - await publisher.publish(Buffer.from(name)); - - // Wait for logs to become consistent - await new Promise(resolve => setTimeout(resolve, 15000)); + // Mock Pub/Sub call, as the emulator doesn't listen to Pub/Sub topics + const encodedName = Buffer.from(name).toString(`base64`); + const data = JSON.stringify({ data: encodedName }); + childProcess.execSync(`functions call helloPubSub --data '${data}'`); - // Check logs after a delay - const logs = childProcess.execSync(`${baseCmd} logs read helloPubSub --start-time ${startTime}`).toString(); + // Check the emulator's logs + const logs = childProcess.execSync(`functions logs read helloPubSub --start-time ${startTime}`).toString(); t.true(logs.includes(`Hello, ${name}!`)); }); @@ -45,16 +37,11 @@ test(`helloPubSub: should print hello world`, async (t) => { t.plan(1); const startTime = new Date(Date.now()).toISOString(); - // Publish to pub/sub topic - const topic = pubsub.topic(topicName); - const publisher = topic.publisher(); - await publisher.publish(Buffer.from(''), { a: 'b' }); - - // Wait for logs to become consistent - await new Promise(resolve => setTimeout(resolve, 15000)); + // Mock Pub/Sub call, as the emulator doesn't listen to Pub/Sub topics + childProcess.execSync(`functions call helloPubSub --data {}`); - // Check logs after a delay - const logs = childProcess.execSync(`${baseCmd} logs read helloPubSub --start-time ${startTime}`).toString(); - t.true(logs.includes('Hello, World!')); + // Check the emulator's logs + const logs = childProcess.execSync(`functions logs read helloPubSub --start-time ${startTime}`).toString(); + t.true(logs.includes(`Hello, World!`)); }); -// [END functions_pubsub_integration_test] +// [END functions_pubsub_system_test] diff --git a/functions/helloworld/test/sample.integration.storage.test.js b/functions/helloworld/test/sample.integration.storage.test.js index 5957bd34dd..2152f6decb 100644 --- a/functions/helloworld/test/sample.integration.storage.test.js +++ b/functions/helloworld/test/sample.integration.storage.test.js @@ -13,66 +13,65 @@ * limitations under the License. */ -const Storage = require(`@google-cloud/storage`); -const storage = Storage(); -const uuid = require(`uuid`); -const test = require(`ava`); -const path = require(`path`); +// [START functions_storage_system_test] const childProcess = require(`child_process`); -const localFileName = `test.txt`; - -// Use unique GCS filename to avoid conflicts between concurrent test runs -const gcsFileName = `test-${uuid.v4()}.txt`; - -const bucketName = process.env.BUCKET_NAME; -const bucket = storage.bucket(bucketName); -const baseCmd = `gcloud beta functions`; +const test = require(`ava`); +const uuid = require(`uuid`); -test.serial(`helloGCS: should print uploaded message`, async (t) => { +test(`helloGCS: should print uploaded message`, async (t) => { t.plan(1); const startTime = new Date(Date.now()).toISOString(); + const filename = uuid.v4(); // Use a unique filename to avoid conflicts - // Upload file - const filepath = path.join(__dirname, localFileName); - await bucket.upload(filepath, { - destination: gcsFileName + // Mock GCS call, as the emulator doesn't listen to GCS buckets + const data = JSON.stringify({ + name: filename, + resourceState: 'exists', + metageneration: '1' }); - // Wait for consistency - await new Promise(resolve => setTimeout(resolve, 15000)); + childProcess.execSync(`functions call helloGCS --data '${data}'`); - // Check logs - const logs = childProcess.execSync(`${baseCmd} logs read helloGCS --start-time ${startTime}`).toString(); - t.true(logs.includes(`File ${gcsFileName} uploaded`)); + // Check the emulator's logs + const logs = childProcess.execSync(`functions logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${filename} uploaded.`)); }); -test.serial(`helloGCS: should print metadata updated message`, async (t) => { +test(`helloGCS: should print metadata updated message`, async (t) => { t.plan(1); const startTime = new Date(Date.now()).toISOString(); + const filename = uuid.v4(); // Use a unique filename to avoid conflicts - // Update file metadata - const file = bucket.file(gcsFileName); - await file.setMetadata(gcsFileName, { foo: `bar` }); + // Mock GCS call, as the emulator doesn't listen to GCS buckets + const data = JSON.stringify({ + name: filename, + resourceState: 'exists', + metageneration: '2' + }); - // Wait for consistency - await new Promise(resolve => setTimeout(resolve, 15000)); + childProcess.execSync(`functions call helloGCS --data '${data}'`); - // Check logs - const logs = childProcess.execSync(`${baseCmd} logs read helloGCS --start-time ${startTime}`).toString(); - t.true(logs.includes(`File ${gcsFileName} metadata updated`)); + // Check the emulator's logs + const logs = childProcess.execSync(`functions logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${filename} metadata updated.`)); }); -test.serial(`helloGCS: should print deleted message`, async (t) => { +test(`helloGCS: should print deleted message`, async (t) => { t.plan(1); const startTime = new Date(Date.now()).toISOString(); + const filename = uuid.v4(); // Use a unique filename to avoid conflicts - // Delete file - bucket.deleteFiles(); + // Mock GCS call, as the emulator doesn't listen to GCS buckets + const data = JSON.stringify({ + name: filename, + resourceState: 'not_exists', + metageneration: '3' + }); - // Wait for consistency - await new Promise(resolve => setTimeout(resolve, 15000)); + childProcess.execSync(`functions call helloGCS --data '${data}'`); - // Check logs - const logs = childProcess.execSync(`${baseCmd} logs read helloGCS --start-time ${startTime}`).toString(); - t.true(logs.includes(`File ${gcsFileName} deleted`)); + // Check the emulator's logs + const logs = childProcess.execSync(`functions logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${filename} deleted.`)); }); +// [END functions_storage_system_test] diff --git a/functions/helloworld/test/sample.system.pubsub.test.js b/functions/helloworld/test/sample.system.pubsub.test.js index 938b454397..b38ba2f9d9 100644 --- a/functions/helloworld/test/sample.system.pubsub.test.js +++ b/functions/helloworld/test/sample.system.pubsub.test.js @@ -13,23 +13,31 @@ * limitations under the License. */ -// [START functions_pubsub_system_test] +// [START functions_pubsub_integration_test] const childProcess = require(`child_process`); const test = require(`ava`); const uuid = require(`uuid`); +const Pubsub = require(`@google-cloud/pubsub`); +const pubsub = Pubsub(); + +const topicName = process.env.FUNCTIONS_TOPIC; +const baseCmd = `gcloud beta functions`; test(`helloPubSub: should print a name`, async (t) => { t.plan(1); const startTime = new Date(Date.now()).toISOString(); const name = uuid.v4(); - // Mock Pub/Sub call, as the emulator doesn't listen to Pub/Sub topics - const encodedName = Buffer.from(name).toString(`base64`); - const data = JSON.stringify({ data: encodedName }); - childProcess.execSync(`functions call helloPubSub --data '${data}'`); + // Publish to pub/sub topic + const topic = pubsub.topic(topicName); + const publisher = topic.publisher(); + await publisher.publish(Buffer.from(name)); + + // Wait for logs to become consistent + await new Promise(resolve => setTimeout(resolve, 15000)); - // Check the emulator's logs - const logs = childProcess.execSync(`functions logs read helloPubSub --start-time ${startTime}`).toString(); + // Check logs after a delay + const logs = childProcess.execSync(`${baseCmd} logs read helloPubSub --start-time ${startTime}`).toString(); t.true(logs.includes(`Hello, ${name}!`)); }); @@ -37,11 +45,16 @@ test(`helloPubSub: should print hello world`, async (t) => { t.plan(1); const startTime = new Date(Date.now()).toISOString(); - // Mock Pub/Sub call, as the emulator doesn't listen to Pub/Sub topics - childProcess.execSync(`functions call helloPubSub --data {}`); + // Publish to pub/sub topic + const topic = pubsub.topic(topicName); + const publisher = topic.publisher(); + await publisher.publish(Buffer.from(''), { a: 'b' }); + + // Wait for logs to become consistent + await new Promise(resolve => setTimeout(resolve, 15000)); - // Check the emulator's logs - const logs = childProcess.execSync(`functions logs read helloPubSub --start-time ${startTime}`).toString(); - t.true(logs.includes(`Hello, World!`)); + // Check logs after a delay + const logs = childProcess.execSync(`${baseCmd} logs read helloPubSub --start-time ${startTime}`).toString(); + t.true(logs.includes('Hello, World!')); }); -// [END functions_pubsub_system_test] +// [END functions_pubsub_integration_test] diff --git a/functions/helloworld/test/sample.system.storage.test.js b/functions/helloworld/test/sample.system.storage.test.js index 2152f6decb..5957bd34dd 100644 --- a/functions/helloworld/test/sample.system.storage.test.js +++ b/functions/helloworld/test/sample.system.storage.test.js @@ -13,65 +13,66 @@ * limitations under the License. */ -// [START functions_storage_system_test] -const childProcess = require(`child_process`); -const test = require(`ava`); +const Storage = require(`@google-cloud/storage`); +const storage = Storage(); const uuid = require(`uuid`); +const test = require(`ava`); +const path = require(`path`); +const childProcess = require(`child_process`); +const localFileName = `test.txt`; -test(`helloGCS: should print uploaded message`, async (t) => { +// Use unique GCS filename to avoid conflicts between concurrent test runs +const gcsFileName = `test-${uuid.v4()}.txt`; + +const bucketName = process.env.BUCKET_NAME; +const bucket = storage.bucket(bucketName); +const baseCmd = `gcloud beta functions`; + +test.serial(`helloGCS: should print uploaded message`, async (t) => { t.plan(1); const startTime = new Date(Date.now()).toISOString(); - const filename = uuid.v4(); // Use a unique filename to avoid conflicts - // Mock GCS call, as the emulator doesn't listen to GCS buckets - const data = JSON.stringify({ - name: filename, - resourceState: 'exists', - metageneration: '1' + // Upload file + const filepath = path.join(__dirname, localFileName); + await bucket.upload(filepath, { + destination: gcsFileName }); - childProcess.execSync(`functions call helloGCS --data '${data}'`); + // Wait for consistency + await new Promise(resolve => setTimeout(resolve, 15000)); - // Check the emulator's logs - const logs = childProcess.execSync(`functions logs read helloGCS --start-time ${startTime}`).toString(); - t.true(logs.includes(`File ${filename} uploaded.`)); + // Check logs + const logs = childProcess.execSync(`${baseCmd} logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${gcsFileName} uploaded`)); }); -test(`helloGCS: should print metadata updated message`, async (t) => { +test.serial(`helloGCS: should print metadata updated message`, async (t) => { t.plan(1); const startTime = new Date(Date.now()).toISOString(); - const filename = uuid.v4(); // Use a unique filename to avoid conflicts - // Mock GCS call, as the emulator doesn't listen to GCS buckets - const data = JSON.stringify({ - name: filename, - resourceState: 'exists', - metageneration: '2' - }); + // Update file metadata + const file = bucket.file(gcsFileName); + await file.setMetadata(gcsFileName, { foo: `bar` }); - childProcess.execSync(`functions call helloGCS --data '${data}'`); + // Wait for consistency + await new Promise(resolve => setTimeout(resolve, 15000)); - // Check the emulator's logs - const logs = childProcess.execSync(`functions logs read helloGCS --start-time ${startTime}`).toString(); - t.true(logs.includes(`File ${filename} metadata updated.`)); + // Check logs + const logs = childProcess.execSync(`${baseCmd} logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${gcsFileName} metadata updated`)); }); -test(`helloGCS: should print deleted message`, async (t) => { +test.serial(`helloGCS: should print deleted message`, async (t) => { t.plan(1); const startTime = new Date(Date.now()).toISOString(); - const filename = uuid.v4(); // Use a unique filename to avoid conflicts - // Mock GCS call, as the emulator doesn't listen to GCS buckets - const data = JSON.stringify({ - name: filename, - resourceState: 'not_exists', - metageneration: '3' - }); + // Delete file + bucket.deleteFiles(); - childProcess.execSync(`functions call helloGCS --data '${data}'`); + // Wait for consistency + await new Promise(resolve => setTimeout(resolve, 15000)); - // Check the emulator's logs - const logs = childProcess.execSync(`functions logs read helloGCS --start-time ${startTime}`).toString(); - t.true(logs.includes(`File ${filename} deleted.`)); + // Check logs + const logs = childProcess.execSync(`${baseCmd} logs read helloGCS --start-time ${startTime}`).toString(); + t.true(logs.includes(`File ${gcsFileName} deleted`)); }); -// [END functions_storage_system_test] From 0b4d2831cf62a31159f8bf681c4fc7ad5f304fdf Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 17 Jan 2018 13:20:48 -0800 Subject: [PATCH 12/21] Fix region tags --- functions/helloworld/test/sample.integration.pubsub.test.js | 4 ++-- functions/helloworld/test/sample.integration.storage.test.js | 4 ++-- functions/helloworld/test/sample.system.pubsub.test.js | 4 ++-- functions/helloworld/test/sample.system.storage.test.js | 2 ++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/functions/helloworld/test/sample.integration.pubsub.test.js b/functions/helloworld/test/sample.integration.pubsub.test.js index 938b454397..10442445ab 100644 --- a/functions/helloworld/test/sample.integration.pubsub.test.js +++ b/functions/helloworld/test/sample.integration.pubsub.test.js @@ -13,7 +13,7 @@ * limitations under the License. */ -// [START functions_pubsub_system_test] +// [START functions_pubsub_integration_test] const childProcess = require(`child_process`); const test = require(`ava`); const uuid = require(`uuid`); @@ -44,4 +44,4 @@ test(`helloPubSub: should print hello world`, async (t) => { const logs = childProcess.execSync(`functions logs read helloPubSub --start-time ${startTime}`).toString(); t.true(logs.includes(`Hello, World!`)); }); -// [END functions_pubsub_system_test] +// [END functions_pubsub_integration_test] diff --git a/functions/helloworld/test/sample.integration.storage.test.js b/functions/helloworld/test/sample.integration.storage.test.js index 2152f6decb..c7361e2e64 100644 --- a/functions/helloworld/test/sample.integration.storage.test.js +++ b/functions/helloworld/test/sample.integration.storage.test.js @@ -13,7 +13,7 @@ * limitations under the License. */ -// [START functions_storage_system_test] +// [START functions_storage_integration_test] const childProcess = require(`child_process`); const test = require(`ava`); const uuid = require(`uuid`); @@ -74,4 +74,4 @@ test(`helloGCS: should print deleted message`, async (t) => { const logs = childProcess.execSync(`functions logs read helloGCS --start-time ${startTime}`).toString(); t.true(logs.includes(`File ${filename} deleted.`)); }); -// [END functions_storage_system_test] +// [END functions_storage_integration_test] diff --git a/functions/helloworld/test/sample.system.pubsub.test.js b/functions/helloworld/test/sample.system.pubsub.test.js index b38ba2f9d9..0fa7b25370 100644 --- a/functions/helloworld/test/sample.system.pubsub.test.js +++ b/functions/helloworld/test/sample.system.pubsub.test.js @@ -13,7 +13,7 @@ * limitations under the License. */ -// [START functions_pubsub_integration_test] +// [START functions_pubsub_system_test] const childProcess = require(`child_process`); const test = require(`ava`); const uuid = require(`uuid`); @@ -57,4 +57,4 @@ test(`helloPubSub: should print hello world`, async (t) => { const logs = childProcess.execSync(`${baseCmd} logs read helloPubSub --start-time ${startTime}`).toString(); t.true(logs.includes('Hello, World!')); }); -// [END functions_pubsub_integration_test] +// [END functions_pubsub_system_test] diff --git a/functions/helloworld/test/sample.system.storage.test.js b/functions/helloworld/test/sample.system.storage.test.js index 5957bd34dd..37f2e93743 100644 --- a/functions/helloworld/test/sample.system.storage.test.js +++ b/functions/helloworld/test/sample.system.storage.test.js @@ -13,6 +13,7 @@ * limitations under the License. */ +// [START functions_storage_system_test] const Storage = require(`@google-cloud/storage`); const storage = Storage(); const uuid = require(`uuid`); @@ -76,3 +77,4 @@ test.serial(`helloGCS: should print deleted message`, async (t) => { const logs = childProcess.execSync(`${baseCmd} logs read helloGCS --start-time ${startTime}`).toString(); t.true(logs.includes(`File ${gcsFileName} deleted`)); }); +// [START functions_storage_system_test] From 1dfe60b9a37a5be6e9beb5257d1734de45c5e785 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 17 Jan 2018 16:21:08 -0800 Subject: [PATCH 13/21] Add HTTP integration test (duplicate of HTTP system test) --- .../test/sample.integration.http.test.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 functions/helloworld/test/sample.integration.http.test.js diff --git a/functions/helloworld/test/sample.integration.http.test.js b/functions/helloworld/test/sample.integration.http.test.js new file mode 100644 index 0000000000..5e23086b3e --- /dev/null +++ b/functions/helloworld/test/sample.integration.http.test.js @@ -0,0 +1,41 @@ +/** + * 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. + */ + +// [START functions_http_integration_test] +const test = require(`ava`); +const Supertest = require(`supertest`); +const supertest = Supertest(process.env.BASE_URL); + +test.cb(`helloHttp: should print a name`, (t) => { + supertest + .post(`/helloHttp`) + .send({ name: 'John' }) + .expect(200) + .expect((response) => { + t.is(response.text, 'Hello John!'); + }) + .end(t.end); +}); + +test.cb(`helloHttp: should print hello world`, (t) => { + supertest + .get(`/helloHttp`) + .expect(200) + .expect((response) => { + t.is(response.text, `Hello World!`); + }) + .end(t.end); +}); +// [END functions_http_integration_test] From 99edb47d66d009d18e4d6c22a3014e0cdee70865 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 24 Jan 2018 14:59:50 -0800 Subject: [PATCH 14/21] Add cloudbuild.yaml for autodeploy --- functions/autodeploy/cloudbuild.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 functions/autodeploy/cloudbuild.yaml diff --git a/functions/autodeploy/cloudbuild.yaml b/functions/autodeploy/cloudbuild.yaml new file mode 100644 index 0000000000..656f4b20c1 --- /dev/null +++ b/functions/autodeploy/cloudbuild.yaml @@ -0,0 +1,10 @@ +steps: +- name: 'gcr.io/cloud-builders/npm' + args: ['install'] + dir: 'functions/autodeploy' +- name: 'gcr.io/cloud-builders/npm' + args: ['test'] + dir: 'functions/autodeploy' +- name: 'gcr.io/cloud-builders/gcloud' + args: ['beta', 'functions', 'deploy', '[YOUR_FUNCTION_NAME]', '[YOUR_TRIGGER_NAME]'] + dir: 'functions/autodeploy' \ No newline at end of file From b0f810256a7641c7b5684a5f180890426d84e60b Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 31 Jan 2018 16:24:59 -0800 Subject: [PATCH 15/21] Move cloudbuild.yaml to different file + switch to Yarn --- functions/{autodeploy => ci_cd}/cloudbuild.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename functions/{autodeploy => ci_cd}/cloudbuild.yaml (88%) diff --git a/functions/autodeploy/cloudbuild.yaml b/functions/ci_cd/cloudbuild.yaml similarity index 88% rename from functions/autodeploy/cloudbuild.yaml rename to functions/ci_cd/cloudbuild.yaml index 656f4b20c1..4da8a2d629 100644 --- a/functions/autodeploy/cloudbuild.yaml +++ b/functions/ci_cd/cloudbuild.yaml @@ -1,5 +1,5 @@ steps: -- name: 'gcr.io/cloud-builders/npm' +- name: 'gcr.io/cloud-builders/yarn' args: ['install'] dir: 'functions/autodeploy' - name: 'gcr.io/cloud-builders/npm' From 2f0643c0c39e54e67806c38e404f6f79128997d5 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 31 Jan 2018 17:00:22 -0800 Subject: [PATCH 16/21] Fix typo vis-a-vis docs --- functions/ci_cd/cloudbuild.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/ci_cd/cloudbuild.yaml b/functions/ci_cd/cloudbuild.yaml index 4da8a2d629..41de4c6c77 100644 --- a/functions/ci_cd/cloudbuild.yaml +++ b/functions/ci_cd/cloudbuild.yaml @@ -6,5 +6,5 @@ steps: args: ['test'] dir: 'functions/autodeploy' - name: 'gcr.io/cloud-builders/gcloud' - args: ['beta', 'functions', 'deploy', '[YOUR_FUNCTION_NAME]', '[YOUR_TRIGGER_NAME]'] + args: ['beta', 'functions', 'deploy', '[YOUR_FUNCTION_NAME]', '[YOUR_FUNCTION_TRIGGER]'] dir: 'functions/autodeploy' \ No newline at end of file From 5607c5aa5fa8c63c0710b74c168bb4e3397bbc65 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Tue, 6 Feb 2018 16:29:00 -0800 Subject: [PATCH 17/21] Add missing gcloud installation cmd --- circle.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/circle.yml b/circle.yml index 780f05a5d5..aa1ea0ed76 100644 --- a/circle.yml +++ b/circle.yml @@ -31,6 +31,7 @@ dependencies: override: - echo $KEYFILE > /home/ubuntu/nodejs-docs-samples/key.json - gcloud auth activate-service-account --key-file /home/ubuntu/nodejs-docs-samples/key.json || true + - gcloud components install beta -q - yarn global add ava nyc codecov semistandard @google-cloud/nodejs-repo-tools@1.4.17 @google-cloud/functions-emulator@1.0.0-alpha.29 - yarn install - yarn run lint From 205f8d8839b7394b59da40b52cae78647b9efa1b Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 7 Feb 2018 16:18:20 -0800 Subject: [PATCH 18/21] Try adding 'sudo' --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index d87e33d17e..1169f6385b 100644 --- a/circle.yml +++ b/circle.yml @@ -31,7 +31,7 @@ dependencies: override: - echo $KEYFILE > /home/ubuntu/nodejs-docs-samples/key.json - gcloud auth activate-service-account --key-file /home/ubuntu/nodejs-docs-samples/key.json || true - - gcloud components install beta -q + - sudo gcloud components install beta -q - yarn global add ava nyc codecov semistandard @google-cloud/nodejs-repo-tools@1.4.17 @google-cloud/functions-emulator@1.0.0-alpha.29 - yarn install - yarn run lint From ffe0cbe743f0c9561e36f0664858f499a04bbc41 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 7 Feb 2018 16:38:18 -0800 Subject: [PATCH 19/21] Remove system tests from circleCI --- circle.yml | 1 - functions/helloworld/package.json | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/circle.yml b/circle.yml index 1169f6385b..0b1266544a 100644 --- a/circle.yml +++ b/circle.yml @@ -31,7 +31,6 @@ dependencies: override: - echo $KEYFILE > /home/ubuntu/nodejs-docs-samples/key.json - gcloud auth activate-service-account --key-file /home/ubuntu/nodejs-docs-samples/key.json || true - - sudo gcloud components install beta -q - yarn global add ava nyc codecov semistandard @google-cloud/nodejs-repo-tools@1.4.17 @google-cloud/functions-emulator@1.0.0-alpha.29 - yarn install - yarn run lint diff --git a/functions/helloworld/package.json b/functions/helloworld/package.json index 42ffb0c51c..4bf09166b5 100644 --- a/functions/helloworld/package.json +++ b/functions/helloworld/package.json @@ -15,8 +15,8 @@ "lint": "repo-tools lint", "pretest": "npm run lint", "e2e-test": "export FUNCTIONS_CMD='gcloud beta functions' && sh test/updateFunctions.sh && BASE_URL=\"https://$GCF_REGION-$GCLOUD_PROJECT.cloudfunctions.net/\" ava -T 20s --verbose test/*.test.js", - "system-test": "export FUNCTIONS_CMD='functions' && sh test/updateFunctions.sh && export BASE_URL=\"http://localhost:8010/$GCLOUD_PROJECT/$GCF_REGION\" && ava -T 20s --verbose test/*.test.js", - "test": "npm run system-test" + "test": "export FUNCTIONS_CMD='functions' && sh test/updateFunctions.sh && export BASE_URL=\"http://localhost:8010/$GCLOUD_PROJECT/$GCF_REGION\" && ava -T 20s --verbose test/index.test.js test/*unit*test.js test/*integration*test.js", + "system-test": "export FUNCTIONS_CMD='functions' && sh test/updateFunctions.sh && export BASE_URL=\"http://localhost:8010/$GCLOUD_PROJECT/$GCF_REGION\" && ava -T 20s --verbose test/*.test.js" }, "dependencies": { "@google-cloud/debug-agent": "2.3.0", From dd0f6105b7bcacd3ccc8d7086d96fd59f70b6577 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 7 Feb 2018 17:00:25 -0800 Subject: [PATCH 20/21] Missed a spot --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 0b1266544a..4de5f32769 100644 --- a/circle.yml +++ b/circle.yml @@ -68,7 +68,7 @@ dependencies: test: override: - functions start && cd functions/datastore && npm run system-test - - functions start && cd functions/helloworld && npm run system-test + - functions start && cd functions/helloworld && npm run test - samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/background/test/**/*.test.js' - samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/gcs/test/**/*.test.js' - samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/http/test/**/*.test.js' From 97488a2b2b4a2604381df5e8ef570f3affc7252d Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Thu, 8 Feb 2018 11:46:05 -0800 Subject: [PATCH 21/21] Add functions-stop command + fix package.json --- circle.yml | 4 ++-- functions/helloworld/package.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/circle.yml b/circle.yml index 4de5f32769..b4341ee6bd 100644 --- a/circle.yml +++ b/circle.yml @@ -67,8 +67,8 @@ dependencies: # Run your tests test: override: - - functions start && cd functions/datastore && npm run system-test - - functions start && cd functions/helloworld && npm run test + - functions start && cd functions/datastore && npm run system-test && functions stop + - functions start && cd functions/helloworld && npm run test && functions stop - samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/background/test/**/*.test.js' - samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/gcs/test/**/*.test.js' - samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/http/test/**/*.test.js' diff --git a/functions/helloworld/package.json b/functions/helloworld/package.json index 4bf09166b5..fd3c51cd1e 100644 --- a/functions/helloworld/package.json +++ b/functions/helloworld/package.json @@ -24,7 +24,6 @@ "safe-buffer": "5.1.1" }, "devDependencies": { - "@google-cloud/functions-emulator": "^1.0.0-alpha.29", "@google-cloud/nodejs-repo-tools": "2.1.3", "@google-cloud/pubsub": "^0.15.0", "@google-cloud/storage": "^1.5.0",