Skip to content

Commit 3388fb7

Browse files
authored
fix: relax strictEqual to match RegExp (#566)
* Relax strictEqual to match RegExp * assert.include * use assert.include * npm run fix * fix: await was accidentally removed causing tests to break * Revert "npm run fix" This reverts commit f146825. * npm run fix * remove await before execSync * is it execa? * use cp.exec for sync-pull test because it might be blocking io * return the Promise * fix listen to error test - process exited 0, didn`t have Error * uninstall execa; * npm run fix * clean up
1 parent 915febd commit 3388fb7

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

samples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"author": "Google Inc.",
99
"repository": "googleapis/nodejs-pubsub",
1010
"engines": {
11-
"node": ">=8"
11+
"node": ">=10"
1212
},
1313
"scripts": {
1414
"test": "mocha system-test --timeout 600000"

samples/system-test/quickstart.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ describe('quickstart', () => {
3333

3434
it('should run the quickstart', async () => {
3535
const stdout = execSync(`node quickstart ${projectId} ${topicName}`);
36-
assert.match(stdout, /^Topic .* created.$/);
36+
assert.match(stdout, /^Topic .* created./);
3737
});
3838
});

samples/system-test/subscriptions.test.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@
1616
'use strict';
1717

1818
const {PubSub} = require('@google-cloud/pubsub');
19+
const assertRejects = require('assert').rejects;
1920
const {assert} = require('chai');
2021
const cp = require('child_process');
2122
const uuid = require('uuid');
2223

2324
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
25+
const execPromise = cmd =>
26+
new Promise((resolve, reject) => {
27+
cp.exec(cmd, {encoding: 'utf-8'}, (err, stdout, stderr) => {
28+
if (err) {
29+
err.stderr = stderr;
30+
return reject(err);
31+
}
32+
resolve(stdout);
33+
});
34+
});
2435

2536
describe('subscriptions', () => {
2637
const projectId = process.env.GCLOUD_PROJECT;
@@ -58,7 +69,7 @@ describe('subscriptions', () => {
5869
const output = execSync(
5970
`${cmd} create ${topicNameOne} ${subscriptionNameOne}`
6071
);
61-
assert.strictEqual(output, `Subscription ${subscriptionNameOne} created.`);
72+
assert.include(output, `Subscription ${subscriptionNameOne} created.`);
6273
const [subscriptions] = await pubsub.topic(topicNameOne).getSubscriptions();
6374
assert.strictEqual(subscriptions[0].name, fullSubscriptionNameOne);
6475
});
@@ -67,7 +78,7 @@ describe('subscriptions', () => {
6778
const output = execSync(
6879
`${cmd} create-push ${topicNameOne} ${subscriptionNameTwo}`
6980
);
70-
assert.strictEqual(output, `Subscription ${subscriptionNameTwo} created.`);
81+
assert.include(output, `Subscription ${subscriptionNameTwo} created.`);
7182
const [subscriptions] = await pubsub.topic(topicNameOne).getSubscriptions();
7283
assert(subscriptions.some(s => s.name === fullSubscriptionNameTwo));
7384
});
@@ -76,7 +87,7 @@ describe('subscriptions', () => {
7687
const output = execSync(
7788
`${cmd} modify-config ${topicNameTwo} ${subscriptionNameTwo}`
7889
);
79-
assert.strictEqual(
90+
assert.include(
8091
output,
8192
`Modified push config for subscription ${subscriptionNameTwo}.`
8293
);
@@ -89,7 +100,7 @@ describe('subscriptions', () => {
89100
`\nTopic: ${fullTopicNameOne}` +
90101
`\nPush config: ` +
91102
`\nAck deadline: 10s`;
92-
assert.strictEqual(output, expected);
103+
assert.include(output, expected);
93104
});
94105

95106
it('should list all subscriptions', async () => {
@@ -116,7 +127,7 @@ describe('subscriptions', () => {
116127

117128
it('should listen for messages synchronously', async () => {
118129
pubsub.topic(topicNameOne).publish(Buffer.from(`Hello, world!`));
119-
const output = execSync(
130+
const output = await execPromise(
120131
`${cmd} sync-pull ${projectId} ${subscriptionNameOne}`
121132
);
122133
assert.match(output, /Done./);
@@ -184,9 +195,10 @@ describe('subscriptions', () => {
184195
});
185196

186197
it('should listen for error messages', async () => {
187-
assert.throws(() => {
188-
execSync(`${cmd} listen-errors nonexistent-subscription`);
189-
}, /Resource not found/);
198+
assertRejects(
199+
() => execPromise(`${cmd} listen-errors nonexistent-subscription`),
200+
/Resource not found/
201+
);
190202
});
191203

192204
it('should set the IAM policy for a subscription', async () => {
@@ -212,7 +224,7 @@ describe('subscriptions', () => {
212224
.subscription(subscriptionNameOne)
213225
.iam.getPolicy();
214226
const output = execSync(`${cmd} get-policy ${subscriptionNameOne}`);
215-
assert.strictEqual(
227+
assert.include(
216228
output,
217229
`Policy for subscription: ${JSON.stringify(results[0].bindings)}.`
218230
);
@@ -225,7 +237,7 @@ describe('subscriptions', () => {
225237

226238
it('should delete a subscription', async () => {
227239
const output = execSync(`${cmd} delete ${subscriptionNameOne}`);
228-
assert.strictEqual(output, `Subscription ${subscriptionNameOne} deleted.`);
240+
assert.include(output, `Subscription ${subscriptionNameOne} deleted.`);
229241
const [subscriptions] = await pubsub.getSubscriptions();
230242
assert.ok(subscriptions);
231243
assert(subscriptions.every(s => s.name !== fullSubscriptionNameOne));
@@ -235,7 +247,7 @@ describe('subscriptions', () => {
235247
const output = execSync(
236248
`${cmd} create-flow ${topicNameTwo} ${subscriptionNameFour} -m 5 -b 1024`
237249
);
238-
assert.strictEqual(
250+
assert.include(
239251
output,
240252
`Subscription ${fullSubscriptionNameFour} created with a maximum of 5 unprocessed messages.`
241253
);

samples/system-test/topics.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('topics', () => {
7777

7878
it('should create a topic', async () => {
7979
const output = execSync(`${cmd} create ${topicNameOne}`);
80-
assert.strictEqual(output, `Topic ${topicNameOne} created.`);
80+
assert.include(output, `Topic ${topicNameOne} created.`);
8181
const [topics] = await pubsub.getTopics();
8282
assert(topics.some(t => t.name === fullTopicNameOne));
8383
});
@@ -208,7 +208,7 @@ describe('topics', () => {
208208
it('should get the IAM policy for a topic', async () => {
209209
const [policy] = await pubsub.topic(topicNameOne).iam.getPolicy();
210210
const output = execSync(`${cmd} get-policy ${topicNameOne}`);
211-
assert.strictEqual(
211+
assert.include(
212212
output,
213213
`Policy for topic: ${JSON.stringify(policy.bindings)}.`
214214
);
@@ -221,7 +221,7 @@ describe('topics', () => {
221221

222222
it('should delete a topic', async () => {
223223
const output = execSync(`${cmd} delete ${topicNameOne}`);
224-
assert.strictEqual(output, `Topic ${topicNameOne} deleted.`);
224+
assert.include(output, `Topic ${topicNameOne} deleted.`);
225225
const [topics] = await pubsub.getTopics();
226226
assert(topics.every(s => s.name !== fullTopicNameOne));
227227
});

0 commit comments

Comments
 (0)