diff --git a/.github/config/nodejs-dev.jsonc b/.github/config/nodejs-dev.jsonc index e1f1e441a7..59967ca7e1 100644 --- a/.github/config/nodejs-dev.jsonc +++ b/.github/config/nodejs-dev.jsonc @@ -146,6 +146,7 @@ "functions/http/httpContent", "functions/http/httpMethods", "functions/http/parseXML", + "functions/imagemagick", "functions/log/helloWorld", "functions/log/processEntry", "functions/memorystore/redis", @@ -173,6 +174,7 @@ "functions/v2/helloGCS", "functions/v2/helloPubSub", "functions/v2/httpLogging", + "functions/v2/imagemagick", "functions/v2/log/processEntry", "functions/v2/ocr/app", "functions/v2/responseStreaming", diff --git a/.github/config/nodejs-prod.jsonc b/.github/config/nodejs-prod.jsonc index 3327a4b159..36bb456a0f 100644 --- a/.github/config/nodejs-prod.jsonc +++ b/.github/config/nodejs-prod.jsonc @@ -89,9 +89,7 @@ "dlp", // [ERR_REQUIRE_ESM]: require() of ES Module "document-ai", // [ERR_REQUIRE_ESM]: require() of ES Module "functions/billing", // (untested) Error: Request failed with status code 500 - "functions/imagemagick", // (untested) Error: A bucket name is needed to use Cloud Storage "functions/slack", // TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type ... Received undefined - "functions/v2/imagemagick", // (untested) 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 "run/idp-sql", // (untested) Error: Invalid contents in the credentials file 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/package.json b/functions/imagemagick/package.json index 016d83e889..cf6fa1cc8b 100644 --- a/functions/imagemagick/package.json +++ b/functions/imagemagick/package.json @@ -12,7 +12,7 @@ "node": ">=12.0.0" }, "scripts": { - "test": "c8 mocha -p -j 2 test/*.test.js --timeout=20000 --exit" + "test": "c8 mocha -p -j 2 test/*.test.js --timeout=30000 --exit" }, "dependencies": { "@google-cloud/storage": "^7.0.0", diff --git a/functions/imagemagick/test/index.test.js b/functions/imagemagick/test/index.test.js index 5aa3b10e17..55fecb924c 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,26 @@ 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('exit', c => (c === 0 ? resolve(stdout) : reject(stderr))); + ffProc.on('exit', code => { + if (code === 0 || code === null) { + // code === null corresponds to a signal-kill + // (which doesn't necessarily indicate a test failure) + resolve(stdout); + } else { + stderr = `Error code: ${code}\n${stderr}`; + reject(new Error(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;