Skip to content

Commit

Permalink
Make tests a little nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace Nassri committed Aug 29, 2017
1 parent 0a39e3e commit bef741f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
29 changes: 14 additions & 15 deletions pubsub/system-test/subscriptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,17 @@ test.serial(`should create a subscription`, async (t) => {
const output = await tools.runAsync(`${cmd} create ${topicNameOne} ${subscriptionNameOne}`, cwd);
t.is(output, `Subscription ${fullSubscriptionNameOne} created.`);
await tools.tryTest(async (assert) => {
const results = await pubsub.topic(topicNameOne).getSubscriptions();
assert.ok(results[0][0]);
assert.equal(results[0][0].name, fullSubscriptionNameOne);
const [subscriptions] = await pubsub.topic(topicNameOne).getSubscriptions();
assert.equal(subscriptions[0].name, fullSubscriptionNameOne);
}).start();
});

test.serial(`should create a push subscription`, async (t) => {
const output = await tools.runAsync(`${cmd} create-push ${topicNameOne} ${subscriptionNameTwo}`, cwd);
t.is(output, `Subscription ${fullSubscriptionNameTwo} created.`);
await tools.tryTest(async (assert) => {
const results = await pubsub.topic(topicNameOne).getSubscriptions();
assert(results[0].some((s) => s.name === fullSubscriptionNameTwo));
const [subscriptions] = await pubsub.topic(topicNameOne).getSubscriptions();
assert(subscriptions.some((s) => s.name === fullSubscriptionNameTwo));
}).start();
});

Expand Down Expand Up @@ -127,20 +126,20 @@ test.serial(`should listen for ordered messages`, async (t) => {
const publisherTwo = pubsub.topic(topicNameTwo).publisher();

await pubsub.topic(topicNameTwo).createSubscription(subscriptionNameThree);
let results = await publisherTwo.publish(expectedBuffer, { counterId: '3' });
publishedMessageIds.push(results[0]);
let [result] = await publisherTwo.publish(expectedBuffer, { counterId: '3' });
publishedMessageIds.push(result);
await subscriptions.listenForOrderedMessages(subscriptionNameThree, timeout);
t.is(console.log.callCount, 0);

results = await publisherTwo.publish(expectedBuffer, { counterId: '1' });
publishedMessageIds.push(results[0]);
[result] = await publisherTwo.publish(expectedBuffer, { counterId: '1' });
publishedMessageIds.push(result);
await subscriptions.listenForOrderedMessages(subscriptionNameThree, timeout);
t.is(console.log.callCount, 1);
t.deepEqual(console.log.firstCall.args, [`* %d %j %j`, publishedMessageIds[1], expected, { counterId: '1' }]);

results = await publisherTwo.publish(expectedBuffer, { counterId: '1' });
results = await publisherTwo.publish(expectedBuffer, { counterId: '2' });
publishedMessageIds.push(results[0]);
[result] = await publisherTwo.publish(expectedBuffer, { counterId: '1' });
[result] = await publisherTwo.publish(expectedBuffer, { counterId: '2' });
publishedMessageIds.push(result);
await tools.tryTest(async (assert) => {
await subscriptions.listenForOrderedMessages(subscriptionNameThree, timeout);
assert.equal(console.log.callCount, 3);
Expand Down Expand Up @@ -181,8 +180,8 @@ test.serial(`should delete a subscription`, async (t) => {
const output = await tools.runAsync(`${cmd} delete ${subscriptionNameOne}`, cwd);
t.is(output, `Subscription ${fullSubscriptionNameOne} deleted.`);
await tools.tryTest(async (assert) => {
const results = await pubsub.getSubscriptions();
assert.ok(results[0]);
assert(results[0].every((s) => s.name !== fullSubscriptionNameOne));
const [subscriptions] = await pubsub.getSubscriptions();
assert.ok(subscriptions);
assert(subscriptions.every((s) => s.name !== fullSubscriptionNameOne));
}).start();
});
12 changes: 5 additions & 7 deletions pubsub/system-test/topics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ test.serial(`should create a topic`, async (t) => {
const output = await tools.runAsync(`${cmd} create ${topicNameOne}`, cwd);
t.is(output, `Topic ${fullTopicNameOne} created.`);
await tools.tryTest(async (assert) => {
const results = await pubsub.getTopics();
assert.ok(results[0]);
assert(results[0].some((s) => s.name === fullTopicNameOne));
const [topics] = await pubsub.getTopics();
assert(topics.some((s) => s.name === fullTopicNameOne));
}).start();
});

Expand Down Expand Up @@ -135,7 +134,7 @@ test.serial(`should publish ordered messages`, async (t) => {
test.serial(`should set the IAM policy for a topic`, async (t) => {
await tools.runAsync(`${cmd} set-policy ${topicNameOne}`, cwd);
const results = await pubsub.topic(topicNameOne).iam.getPolicy();
const policy = results[0];
const [policy] = results;
t.deepEqual(policy.bindings, [
{
role: `roles/pubsub.editor`,
Expand Down Expand Up @@ -164,8 +163,7 @@ test.serial(`should delete a topic`, async (t) => {
const output = await tools.runAsync(`${cmd} delete ${topicNameOne}`, cwd);
t.is(output, `Topic ${fullTopicNameOne} deleted.`);
await tools.tryTest(async (assert) => {
const results = await pubsub.getTopics();
assert.ok(results[0]);
assert(results[0].every((s) => s.name !== fullTopicNameOne));
const [topics] = await pubsub.getTopics();
assert(topics.every((s) => s.name !== fullTopicNameOne));
}).start();
});

0 comments on commit bef741f

Please sign in to comment.