forked from Cox-Automotive/alks-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam_role_test.go
100 lines (76 loc) · 2.07 KB
/
iam_role_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package alks
import (
. "github.com/motain/gocheck"
)
func (s *S) Test_CreateIamRole(c *C) {
testServer.Response(202, nil, iamGetRole)
resp, err := s.client.CreateIamRole("rolebae", "Admin", false)
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(resp, NotNil)
c.Assert(resp.RoleName, Equals, "rolebae")
c.Assert(resp.RoleType, Equals, "Admin")
}
func (s *S) Test_CreateIamTrustRole(c *C) {
testServer.Response(202, nil, iamGetTrustRole)
resp, err := s.client.CreateIamTrustRole("test-cross-role", "Cross Account", "arn:aws:iam::123456789123:role/test-role")
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(resp, NotNil)
c.Assert(resp.RoleName, Equals, "test-cross-role")
c.Assert(resp.RoleType, Equals, "Cross Account")
}
func (s *S) Test_GetIamRole(c *C) {
testServer.Response(202, nil, iamGetRole)
resp, err := s.client.GetIamRole("rolebae")
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(resp, NotNil)
c.Assert(resp.RoleName, Equals, "rolebae")
c.Assert(resp.RoleType, Equals, "Admin")
c.Assert(resp.Exists, Equals, true)
}
func (s *S) Test_GetIamRoleMissing(c *C) {
testServer.Response(202, nil, iamGetRole404)
resp, _ := s.client.GetIamRole("rolebaez")
_ = testServer.WaitRequest()
c.Assert(resp, IsNil)
}
func (s *S) Test_DeleteIamRole(c *C) {
testServer.Response(202, nil, "{}")
err := s.client.DeleteIamRole("rolebaezzzzz")
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
}
var iamGetRole = `
{
"roleName": "rolebae",
"roleType": "Admin",
"roleArn": "aws:arn:foo",
"instanceProfileArn": "aws:arn:foo:ip",
"addedRoleToInstanceProfile": true,
"errors": [],
"roleExists": true
}
`
var iamGetTrustRole = `
{
"roleName": "test-cross-role",
"roleType": "Cross Account",
"roleArn": "aws:arn:foo",
"instanceProfileArn": "aws:arn:foo:ip",
"addedRoleToInstanceProfile": true,
"errors": [],
"roleExists": true
}
`
var iamGetRole404 = `
{
"roleName": "",
"roleType": "",
"roleArn": "",
"instanceProfileArn": "",
"errors": [],
"roleExists": false
}
`