Skip to content

Commit 81abae8

Browse files
tests: factor out resource management from sample system tests (#1544)
* tests: factor out resource management from sample system tests * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 0a4b77c commit 81abae8

File tree

7 files changed

+830
-715
lines changed

7 files changed

+830
-715
lines changed

samples/system-test/openTelemetryTracing.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,31 @@ import {PubSub} from '@google-cloud/pubsub';
1616
import {assert} from 'chai';
1717
import {describe, it, before, after} from 'mocha';
1818
import {execSync} from './common';
19-
import * as uuid from 'uuid';
19+
import {TestResources} from './testResources';
2020

2121
describe('openTelemetry', () => {
2222
const projectId = process.env.GCLOUD_PROJECT;
2323
const pubsub = new PubSub({projectId});
24-
const topicName = `nodejs-docs-samples-test-${uuid.v4()}`;
25-
const subName = `nodejs-docs-samples-test-${uuid.v4()}`;
24+
25+
const resources = new TestResources('quickstart');
26+
const topicName = resources.generateName('ot');
27+
const subName = resources.generateName('ot');
2628

2729
before(async () => {
2830
await pubsub.createTopic(topicName);
2931
await pubsub.topic(topicName).createSubscription(subName);
3032
});
3133

3234
after(async () => {
33-
await pubsub.subscription(subName).delete();
34-
await pubsub.topic(topicName).delete();
35+
const [subscriptions] = await pubsub.getSubscriptions();
36+
await Promise.all(
37+
resources.filterForCleanup(subscriptions).map(x => x.delete?.())
38+
);
39+
40+
const [topics] = await pubsub.getTopics();
41+
await Promise.all(
42+
resources.filterForCleanup(topics).map(x => x.delete?.())
43+
);
3544
});
3645

3746
it('should run the openTelemetryTracing sample', async () => {

samples/system-test/quickstart.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,26 @@ import {PubSub} from '@google-cloud/pubsub';
1616
import {assert} from 'chai';
1717
import {describe, it, after} from 'mocha';
1818
import {execSync} from './common';
19-
import * as uuid from 'uuid';
19+
import {TestResources} from './testResources';
2020

2121
describe('quickstart', () => {
2222
const projectId = process.env.GCLOUD_PROJECT;
2323
const pubsub = new PubSub({projectId});
24-
const topicName = `nodejs-docs-samples-test-${uuid.v4()}`;
25-
const subName = `nodejs-docs-samples-test-${uuid.v4()}`;
24+
25+
const resources = new TestResources('quickstart');
26+
const topicName = resources.generateName('qs');
27+
const subName = resources.generateName('qs');
2628

2729
after(async () => {
28-
await pubsub.subscription(subName).delete();
29-
await pubsub.topic(topicName).delete();
30+
const [subscriptions] = await pubsub.getSubscriptions();
31+
await Promise.all(
32+
resources.filterForCleanup(subscriptions).map(x => x.delete?.())
33+
);
34+
35+
const [topics] = await pubsub.getTopics();
36+
await Promise.all(
37+
resources.filterForCleanup(topics).map(x => x.delete?.())
38+
);
3039
});
3140

3241
it('should run the quickstart', async () => {

0 commit comments

Comments
 (0)