Skip to content

Commit

Permalink
tests: factor out resource management from sample system tests (#1544)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
feywind and gcf-owl-bot[bot] committed May 3, 2022
1 parent 0a4b77c commit 81abae8
Show file tree
Hide file tree
Showing 7 changed files with 830 additions and 715 deletions.
19 changes: 14 additions & 5 deletions samples/system-test/openTelemetryTracing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,31 @@ import {PubSub} from '@google-cloud/pubsub';
import {assert} from 'chai';
import {describe, it, before, after} from 'mocha';
import {execSync} from './common';
import * as uuid from 'uuid';
import {TestResources} from './testResources';

describe('openTelemetry', () => {
const projectId = process.env.GCLOUD_PROJECT;
const pubsub = new PubSub({projectId});
const topicName = `nodejs-docs-samples-test-${uuid.v4()}`;
const subName = `nodejs-docs-samples-test-${uuid.v4()}`;

const resources = new TestResources('quickstart');
const topicName = resources.generateName('ot');
const subName = resources.generateName('ot');

before(async () => {
await pubsub.createTopic(topicName);
await pubsub.topic(topicName).createSubscription(subName);
});

after(async () => {
await pubsub.subscription(subName).delete();
await pubsub.topic(topicName).delete();
const [subscriptions] = await pubsub.getSubscriptions();
await Promise.all(
resources.filterForCleanup(subscriptions).map(x => x.delete?.())
);

const [topics] = await pubsub.getTopics();
await Promise.all(
resources.filterForCleanup(topics).map(x => x.delete?.())
);
});

it('should run the openTelemetryTracing sample', async () => {
Expand Down
19 changes: 14 additions & 5 deletions samples/system-test/quickstart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@ import {PubSub} from '@google-cloud/pubsub';
import {assert} from 'chai';
import {describe, it, after} from 'mocha';
import {execSync} from './common';
import * as uuid from 'uuid';
import {TestResources} from './testResources';

describe('quickstart', () => {
const projectId = process.env.GCLOUD_PROJECT;
const pubsub = new PubSub({projectId});
const topicName = `nodejs-docs-samples-test-${uuid.v4()}`;
const subName = `nodejs-docs-samples-test-${uuid.v4()}`;

const resources = new TestResources('quickstart');
const topicName = resources.generateName('qs');
const subName = resources.generateName('qs');

after(async () => {
await pubsub.subscription(subName).delete();
await pubsub.topic(topicName).delete();
const [subscriptions] = await pubsub.getSubscriptions();
await Promise.all(
resources.filterForCleanup(subscriptions).map(x => x.delete?.())
);

const [topics] = await pubsub.getTopics();
await Promise.all(
resources.filterForCleanup(topics).map(x => x.delete?.())
);
});

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

0 comments on commit 81abae8

Please sign in to comment.