diff --git a/.github/config/nodejs-prod.jsonc b/.github/config/nodejs-prod.jsonc index 85d160e052..f0db660651 100644 --- a/.github/config/nodejs-prod.jsonc +++ b/.github/config/nodejs-prod.jsonc @@ -86,10 +86,8 @@ "eventarc/pubsub", // (untested) Environment Variable 'SERVICE_NAME' not found "functions/billing", // Error: Request failed with status code 500 "functions/http/uploadFile", // npm error Missing script: "test" - "functions/imagemagick", // Error: A bucket name is needed to use Cloud Storage "functions/ocr/app", // Error: Bucket not provided. Make sure you have a "bucket" property in your request "functions/slack", // TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type ... Received undefined - "functions/v2/imagemagick", // Error: A bucket name is needed to use Cloud Storage. "healthcare/fhir", // Error: Cannot find module 'whatwg-url' "iam/deny", // PERMISSION_DENIED: Permission iam.googleapis.com/denypolicies.create denied on resource cloudresourcemanager.googleapis.com/projects/long-door-651 "recaptcha_enterprise/snippets", // Cannot use import statement outside a module diff --git a/functions/imagemagick/ci-setup.json b/functions/imagemagick/ci-setup.json new file mode 100644 index 0000000000..6b5af2ce84 --- /dev/null +++ b/functions/imagemagick/ci-setup.json @@ -0,0 +1,6 @@ +{ + "env": { + "FUNCTIONS_BUCKET": "nodejs-docs-samples-tests", + "BLURRED_BUCKET_NAME": "nodejs-docs-samples-tests-imagick" + } +} diff --git a/functions/imagemagick/test/index.test.js b/functions/imagemagick/test/index.test.js index 5aa3b10e17..9665d878fc 100644 --- a/functions/imagemagick/test/index.test.js +++ b/functions/imagemagick/test/index.test.js @@ -15,7 +15,7 @@ 'use strict'; const assert = require('assert'); -const {spawn} = require('child_process'); +const {execSync, spawn} = require('child_process'); const {Storage} = require('@google-cloud/storage'); const sinon = require('sinon'); const {request} = require('gaxios'); @@ -47,13 +47,18 @@ async function startFF(port) { let stderr = ''; ffProc.stdout.on('data', data => (stdout += data)); ffProc.stderr.on('data', data => (stderr += data)); - ffProc.on('error', reject); + ffProc.on('error', c => (c === 0 ? resolve(stdout) : reject(stderr))); ffProc.on('exit', c => (c === 0 ? resolve(stdout) : reject(stderr))); }); await waitPort({host: 'localhost', port}); return {ffProc, ffProcHandler}; } +// ImageMagick is available by default in Cloud Run Functions environments +// https://cloud.google.com/functions/1stgendocs/tutorials/imagemagick-1st-gen.md#importing_dependencies +// Manually install it for testing only. +execSync('sudo apt-get install imagemagick -y'); + describe('functions/imagemagick tests', () => { before(async () => { let exists; diff --git a/functions/v2/imagemagick/ci-setup.json b/functions/v2/imagemagick/ci-setup.json new file mode 100644 index 0000000000..6b5af2ce84 --- /dev/null +++ b/functions/v2/imagemagick/ci-setup.json @@ -0,0 +1,6 @@ +{ + "env": { + "FUNCTIONS_BUCKET": "nodejs-docs-samples-tests", + "BLURRED_BUCKET_NAME": "nodejs-docs-samples-tests-imagick" + } +} diff --git a/functions/v2/imagemagick/test/integration.test.js b/functions/v2/imagemagick/test/integration.test.js index e0a2ac56d2..82f5b8a43e 100644 --- a/functions/v2/imagemagick/test/integration.test.js +++ b/functions/v2/imagemagick/test/integration.test.js @@ -15,6 +15,7 @@ 'use strict'; const assert = require('assert'); +const {execSync} = require('child_process'); const {Storage} = require('@google-cloud/storage'); const sinon = require('sinon'); const supertest = require('supertest'); @@ -33,6 +34,11 @@ const testFiles = { require('../index'); +// ImageMagick is available by default in Cloud Run Functions environments +// https://cloud.google.com/functions/1stgendocs/tutorials/imagemagick-1st-gen.md#importing_dependencies +// Manually install it for testing only. +execSync('sudo apt-get install imagemagick -y'); + describe('functions/imagemagick tests', () => { before(async () => { let exists;