Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: factor out resource management from sample system tests #1544

Merged
merged 2 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading