1
- const { Before, Given, Then } = require ( "@cucumber/cucumber" ) ;
1
+ const { After , Before, Given, Then } = require ( "@cucumber/cucumber" ) ;
2
2
3
- Before ( { tags : "@iam" } , function ( scenario , callback ) {
3
+ Before ( { tags : "@iam" } , function ( ) {
4
4
const { IAM } = require ( "../../../clients/client-iam" ) ;
5
5
this . iam = new IAM ( { } ) ;
6
- callback ( ) ;
7
6
} ) ;
8
7
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
+ }
32
17
} ) ;
33
18
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 . iamUserArn = "" ;
21
+ this . iamUser = this . uniqueName ( name ) ;
36
22
} ) ;
37
23
38
- Then ( "the IAM user should exist" , function ( callback ) {
39
- this . assert . equal ( this . data . User . UserName , this . iamUser ) ;
40
- callback ( ) ;
24
+ Given ( "I create an IAM user with the username" , async function ( ) {
25
+ try {
26
+ const { User } = await this . iam . createUser ( { UserName : this . iamUser } ) ;
27
+ this . iamUserArn = User . Arn ;
28
+ } catch ( error ) {
29
+ this . error = error ;
30
+ }
41
31
} ) ;
42
32
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
- ) ;
33
+ Then ( "the IAM user should exist" , async function ( ) {
34
+ const { User } = await this . iam . getUser ( { UserName : this . iamUser } ) ;
35
+ this . assert . equal ( User . UserName , this . iamUser ) ;
36
+ this . assert . equal ( User . Arn , this . iamUserArn ) ;
52
37
} ) ;
53
38
54
- Given ( "I create an IAM role with name prefix {string}" , function ( name , callback ) {
39
+ Given ( "I create an IAM role with name prefix {string}" , async function ( name ) {
55
40
this . iamRoleName = this . uniqueName ( name ) ;
56
41
57
- const world = this ;
58
42
const assumeRolePolicyDocument =
59
43
'{"Version":"2008-10-17","Statement":[' +
60
44
'{"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},' +
@@ -63,27 +47,11 @@ Given("I create an IAM role with name prefix {string}", function (name, callback
63
47
RoleName : this . iamRoleName ,
64
48
AssumeRolePolicyDocument : assumeRolePolicyDocument ,
65
49
} ;
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
- } ) ;
74
50
75
- Then ( "the IAM role should exist" , function ( callback ) {
76
- this . assert . compare ( this . iamRoleArn . length , ">" , 0 ) ;
77
- callback ( ) ;
51
+ await this . iam . createRole ( params ) ;
78
52
} ) ;
79
53
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
- ) ;
54
+ Then ( "the IAM role should exist" , async function ( ) {
55
+ const { Role } = await this . iam . getRole ( { RoleName : this . iamRoleName } ) ;
56
+ this . assert . equal ( Role . RoleName , this . iamRoleName ) ;
89
57
} ) ;
0 commit comments