Skip to content

Commit b20dbdb

Browse files
committed
fix(e2e): move delete of IAM resources to After call
1 parent d07097b commit b20dbdb

File tree

2 files changed

+29
-66
lines changed

2 files changed

+29
-66
lines changed

features/iam/iam.feature

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ Feature: IAM
77
Scenario: Users
88
Given I have an IAM username "js-test"
99
And I create an IAM user with the username
10-
And I get the IAM user
1110
Then the IAM user should exist
12-
And I delete the IAM user
1311

1412
Scenario: Roles
1513
Given I create an IAM role with name prefix "aws-sdk-js"
1614
Then the IAM role should exist
17-
And I delete the IAM role
1815

1916
Scenario: Error handling
2017
Given I have an IAM username "js-test-dupe"
2118
And I create an IAM user with the username
2219
And I create an IAM user with the username
2320
Then the error code should be "EntityAlreadyExists"
24-
And I delete the IAM user

features/iam/step_definitions/iam.js

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,43 @@
1-
const { Before, Given, Then } = require("@cucumber/cucumber");
1+
const { After, Before, Given, Then } = require("@cucumber/cucumber");
22

3-
Before({ tags: "@iam" }, function (scenario, callback) {
3+
Before({ tags: "@iam" }, function () {
44
const { IAM } = require("../../../clients/client-iam");
55
this.iam = new IAM({});
6-
callback();
76
});
87

9-
Given("I have an IAM username {string}", function (name, callback) {
10-
this.iamUserArn = "";
11-
this.iamUser = this.uniqueName(name);
12-
callback();
13-
});
14-
15-
Given("I create an IAM user with the username", function (callback) {
16-
const world = this;
17-
const next = function () {
18-
if (world.data) this.iamUserArn = world.data.User.Arn;
19-
else this.iamUserArn = null;
20-
callback();
21-
};
22-
next.fail = callback;
23-
this.request(
24-
"iam",
25-
"createUser",
26-
{
27-
UserName: this.iamUser,
28-
},
29-
next,
30-
false
31-
);
8+
After({ tags: "@iam" }, async function () {
9+
if (this.iamUser) {
10+
await this.iam.deleteUser({ UserName: this.iamUser });
11+
this.iamUser = undefined;
12+
}
13+
if (this.iamRoleName) {
14+
await this.iam.deleteRole({ RoleName: this.iamRoleName });
15+
this.iamRoleName = undefined;
16+
}
3217
});
3318

34-
Given("I get the IAM user", function (callback) {
35-
this.request("iam", "getUser", { UserName: this.iamUser }, callback);
19+
Given("I have an IAM username {string}", function (name) {
20+
this.iamUser = this.uniqueName(name);
3621
});
3722

38-
Then("the IAM user should exist", function (callback) {
39-
this.assert.equal(this.data.User.UserName, this.iamUser);
40-
callback();
23+
Given("I create an IAM user with the username", async function () {
24+
try {
25+
const { User } = await this.iam.createUser({ UserName: this.iamUser });
26+
this.iamUserArn = User.Arn;
27+
} catch (error) {
28+
this.error = error;
29+
}
4130
});
4231

43-
Then("I delete the IAM user", function (callback) {
44-
this.request(
45-
"iam",
46-
"deleteUser",
47-
{
48-
UserName: this.iamUser,
49-
},
50-
callback
51-
);
32+
Then("the IAM user should exist", async function () {
33+
const { User } = await this.iam.getUser({ UserName: this.iamUser });
34+
this.assert.equal(User.UserName, this.iamUser);
35+
this.assert.equal(User.Arn, this.iamUserArn);
5236
});
5337

54-
Given("I create an IAM role with name prefix {string}", function (name, callback) {
38+
Given("I create an IAM role with name prefix {string}", async function (name) {
5539
this.iamRoleName = this.uniqueName(name);
5640

57-
const world = this;
5841
const assumeRolePolicyDocument =
5942
'{"Version":"2008-10-17","Statement":[' +
6043
'{"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},' +
@@ -63,27 +46,11 @@ Given("I create an IAM role with name prefix {string}", function (name, callback
6346
RoleName: this.iamRoleName,
6447
AssumeRolePolicyDocument: assumeRolePolicyDocument,
6548
};
66-
const next = function () {
67-
world.iamRoleArn = world.data.Role.Arn;
68-
callback();
69-
};
70-
next.fail = callback;
71-
72-
this.request("iam", "createRole", params, next);
73-
});
7449

75-
Then("the IAM role should exist", function (callback) {
76-
this.assert.compare(this.iamRoleArn.length, ">", 0);
77-
callback();
50+
await this.iam.createRole(params);
7851
});
7952

80-
Then("I delete the IAM role", function (callback) {
81-
this.request(
82-
"iam",
83-
"deleteRole",
84-
{
85-
RoleName: this.iamRoleName,
86-
},
87-
callback
88-
);
53+
Then("the IAM role should exist", async function () {
54+
const { Role } = await this.iam.getRole({ RoleName: this.iamRoleName });
55+
this.assert.equal(Role.RoleName, this.iamRoleName);
8956
});

0 commit comments

Comments
 (0)