Skip to content

Commit e169459

Browse files
authored
ci(imagemagick): add test isolation for functions imagemagick (GoogleCloudPlatform#3987)
* ci(imagemagick): add test isolation for functions imagemagick * manual install package * debug reject failure * add update to v2 version of same sample * correct import * sudo, lint * wait for completion * add tests to dev config * try bump timeout * adapt ffprochandler from helloGCS test * reduce delta
1 parent 227ac38 commit e169459

File tree

7 files changed

+37
-6
lines changed

7 files changed

+37
-6
lines changed

.github/config/nodejs-dev.jsonc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
"functions/http/httpContent",
147147
"functions/http/httpMethods",
148148
"functions/http/parseXML",
149+
"functions/imagemagick",
149150
"functions/log/helloWorld",
150151
"functions/log/processEntry",
151152
"functions/memorystore/redis",
@@ -173,6 +174,7 @@
173174
"functions/v2/helloGCS",
174175
"functions/v2/helloPubSub",
175176
"functions/v2/httpLogging",
177+
"functions/v2/imagemagick",
176178
"functions/v2/log/processEntry",
177179
"functions/v2/ocr/app",
178180
"functions/v2/responseStreaming",

.github/config/nodejs-prod.jsonc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@
8989
"dlp", // [ERR_REQUIRE_ESM]: require() of ES Module
9090
"document-ai", // [ERR_REQUIRE_ESM]: require() of ES Module
9191
"functions/billing", // (untested) Error: Request failed with status code 500
92-
"functions/imagemagick", // (untested) Error: A bucket name is needed to use Cloud Storage
9392
"functions/slack", // TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type ... Received undefined
94-
"functions/v2/imagemagick", // (untested) Error: A bucket name is needed to use Cloud Storage.
9593
"healthcare/fhir", // Error: Cannot find module 'whatwg-url'
9694
"iam/deny", // PERMISSION_DENIED: Permission iam.googleapis.com/denypolicies.create denied on resource cloudresourcemanager.googleapis.com/projects/long-door-651
9795
"run/idp-sql", // (untested) Error: Invalid contents in the credentials file
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"env": {
3+
"FUNCTIONS_BUCKET": "nodejs-docs-samples-tests",
4+
"BLURRED_BUCKET_NAME": "nodejs-docs-samples-tests-imagick"
5+
}
6+
}

functions/imagemagick/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"node": ">=12.0.0"
1313
},
1414
"scripts": {
15-
"test": "c8 mocha -p -j 2 test/*.test.js --timeout=20000 --exit"
15+
"test": "c8 mocha -p -j 2 test/*.test.js --timeout=30000 --exit"
1616
},
1717
"dependencies": {
1818
"@google-cloud/storage": "^7.0.0",

functions/imagemagick/test/index.test.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'use strict';
1616

1717
const assert = require('assert');
18-
const {spawn} = require('child_process');
18+
const {execSync, spawn} = require('child_process');
1919
const {Storage} = require('@google-cloud/storage');
2020
const sinon = require('sinon');
2121
const {request} = require('gaxios');
@@ -47,13 +47,26 @@ async function startFF(port) {
4747
let stderr = '';
4848
ffProc.stdout.on('data', data => (stdout += data));
4949
ffProc.stderr.on('data', data => (stderr += data));
50-
ffProc.on('error', reject);
51-
ffProc.on('exit', c => (c === 0 ? resolve(stdout) : reject(stderr)));
50+
ffProc.on('exit', code => {
51+
if (code === 0 || code === null) {
52+
// code === null corresponds to a signal-kill
53+
// (which doesn't necessarily indicate a test failure)
54+
resolve(stdout);
55+
} else {
56+
stderr = `Error code: ${code}\n${stderr}`;
57+
reject(new Error(stderr));
58+
}
59+
});
5260
});
5361
await waitPort({host: 'localhost', port});
5462
return {ffProc, ffProcHandler};
5563
}
5664

65+
// ImageMagick is available by default in Cloud Run Functions environments
66+
// https://cloud.google.com/functions/1stgendocs/tutorials/imagemagick-1st-gen.md#importing_dependencies
67+
// Manually install it for testing only.
68+
execSync('sudo apt-get install imagemagick -y');
69+
5770
describe('functions/imagemagick tests', () => {
5871
before(async () => {
5972
let exists;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"env": {
3+
"FUNCTIONS_BUCKET": "nodejs-docs-samples-tests",
4+
"BLURRED_BUCKET_NAME": "nodejs-docs-samples-tests-imagick"
5+
}
6+
}

functions/v2/imagemagick/test/integration.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'use strict';
1616

1717
const assert = require('assert');
18+
const {execSync} = require('child_process');
1819
const {Storage} = require('@google-cloud/storage');
1920
const sinon = require('sinon');
2021
const supertest = require('supertest');
@@ -33,6 +34,11 @@ const testFiles = {
3334

3435
require('../index');
3536

37+
// ImageMagick is available by default in Cloud Run Functions environments
38+
// https://cloud.google.com/functions/1stgendocs/tutorials/imagemagick-1st-gen.md#importing_dependencies
39+
// Manually install it for testing only.
40+
execSync('sudo apt-get install imagemagick -y');
41+
3642
describe('functions/imagemagick tests', () => {
3743
before(async () => {
3844
let exists;

0 commit comments

Comments
 (0)