Skip to content

fix(e2e): delete sns topic in After call #3959

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

Merged
merged 1 commit into from
Sep 15, 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
3 changes: 1 addition & 2 deletions features/sns/sns.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ Feature: Simple Notification Service
I want to use Amazon Simple Notification Service

Scenario: Topics
Given I create an SNS topic with name "aws-js-sdk-integration-topic"
Given I create an SNS topic with prefix "aws-js-sdk"
And I list the SNS topics
Then the list should contain the topic ARN
And I delete the SNS topic

Scenario: Error handling
Given I get SNS topic attributes with an invalid ARN
Expand Down
63 changes: 22 additions & 41 deletions features/sns/step_definitions/sns.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,38 @@
const { Before, Given, Then } = require("@cucumber/cucumber");
const { After, Before, Given, Then } = require("@cucumber/cucumber");

Before({ tags: "@sns" }, function (scenario, callback) {
Before({ tags: "@sns" }, function () {
const { SNS } = require("../../../clients/client-sns");
this.service = new SNS({});
callback();
});

Given("I create an SNS topic with name {string}", function (name, callback) {
const world = this;
this.request(
null,
"createTopic",
{
Name: name,
},
callback,
function (data) {
world.topicArn = data.TopicArn;
}
);
After({ tags: "@sns" }, async function () {
if (this.topicArn) {
await this.service.deleteTopic({ TopicArn: this.topicArn });
this.topicArn = undefined;
}
});

Given("I list the SNS topics", function (callback) {
this.request(null, "listTopics", {}, callback);
Given("I create an SNS topic with prefix {string}", async function (prefix) {
const topicName = this.uniqueName(prefix);
const { TopicArn } = await this.service.createTopic({ Name: topicName });
this.topicArn = TopicArn;
});

Then("the list should contain the topic ARN", function (callback) {
Given("I list the SNS topics", async function () {
this.data = await this.service.listTopics({});
});

Then("the list should contain the topic ARN", function () {
const arn = this.topicArn;
this.assert.contains(this.data.Topics, function (topic) {
return topic.TopicArn === arn;
});
callback();
});

Then("I delete the SNS topic", function (callback) {
this.request(
null,
"deleteTopic",
{
TopicArn: this.topicArn,
},
callback
);
});

Given("I get SNS topic attributes with an invalid ARN", function (callback) {
this.request(
null,
"getTopicAttributes",
{
TopicArn: "INVALID",
},
callback,
false
);
Given("I get SNS topic attributes with an invalid ARN", async function () {
try {
await this.service.getTopicAttributes({ TopicArn: "INVALID" });
} catch (error) {
this.error = error;
}
});