forked from aiven/aiven-go-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
accounts_acc_test.go
190 lines (161 loc) · 5.88 KB
/
accounts_acc_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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package aiven
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"math/rand"
"strconv"
)
var _ = Describe("Accounts", func() {
Context("Check all possible accounts interactions", func() {
// Account
var (
accountName string
account *AccountResponse
err error
)
It("Account creation should not error", func() {
accountName = "test-acc-account-" + strconv.Itoa(rand.Int())
account, err = client.Accounts.Create(Account{Name: accountName})
Expect(err).NotTo(HaveOccurred())
})
It("Account creation should populate fields properly", func() {
Expect(account.Account.Id).NotTo(BeEmpty())
Expect(account.Account.Name).To(Equal(accountName))
Expect(account.Account.CreateTime).NotTo(BeNil())
Expect(account.Account.UpdateTime).NotTo(BeNil())
Expect(account.APIResponse.Message).To(BeEmpty())
Expect(account.APIResponse.Errors).To(BeEmpty())
})
// AccountTeams
var (
teamName string
team *AccountTeamResponse
errT error
)
It("Create account team", func() {
if account == nil {
Fail("account is nil")
}
teamName = "test-acc-team" + strconv.Itoa(rand.Int())
team, errT = client.AccountTeams.Create(account.Account.Id, AccountTeam{
Name: teamName,
})
Expect(errT).NotTo(HaveOccurred())
Expect(team.Team.Id).NotTo(BeEmpty())
Expect(team.Team.Name).To(Equal(teamName))
Expect(team.Team.UpdateTime).NotTo(BeNil())
Expect(team.Team.CreateTime).NotTo(BeNil())
Expect(team.APIResponse.Message).To(BeEmpty())
Expect(team.APIResponse.Errors).To(BeEmpty())
})
// Account members
var (
memberEmail string
errM error
)
It("should not error", func() {
memberEmail = "ivan.savciuc+" + strconv.Itoa(rand.Int()) + "@aiven.io"
errM = client.AccountTeamMembers.Invite(account.Account.Id, team.Team.Id, memberEmail)
Expect(memberEmail).NotTo(BeEmpty())
Expect(errM).NotTo(HaveOccurred())
})
It("should send invite", func() {
invites, errI := client.AccountTeamInvites.List(account.Account.Id, team.Team.Id)
Expect(errI).NotTo(HaveOccurred())
var found bool
for _, invite := range invites.Invites {
if invite.UserEmail == memberEmail {
found = true
}
}
Expect(found).To(Equal(true), "cannot find invitation for newly created member")
if errD := client.AccountTeamInvites.Delete(account.Account.Id, team.Team.Id, memberEmail); errD != nil {
Fail("cannot delete an invitation :" + errD.Error())
}
})
// Account project
var (
projectName string
projectType = "admin"
)
It("Account projects creation ", func() {
projectName = "test-acc-pr" + strconv.Itoa(rand.Int())
By("Create project")
if _, errP := client.Projects.Create(CreateProjectRequest{
Project: projectName,
AccountId: ToStringPointer(account.Account.Id),
}); errP != nil {
Fail("cannot create project :" + errP.Error())
}
By("Create account team project association")
if errTP := client.AccountTeamProjects.Create(
account.Account.Id,
team.Team.Id,
AccountTeamProject{ProjectName: projectName, TeamType: "developer"}); errTP != nil {
Fail("cannot create account team project association:" + errTP.Error())
}
By("Update account team project")
if errTPu := client.AccountTeamProjects.Update(
account.Account.Id,
team.Team.Id,
AccountTeamProject{ProjectName: projectName, TeamType: projectType}); errTPu != nil {
Fail("cannot update account team project:" + errTPu.Error())
}
})
It("Account team project association should be in the list", func() {
projects, errL := client.AccountTeamProjects.List(account.Account.Id, team.Team.Id)
Expect(errL).NotTo(HaveOccurred())
if projects != nil {
var found bool
for _, p := range projects.Projects {
if p.ProjectName == projectName {
Expect(p.TeamType).To(Equal(projectType))
found = true
}
}
Expect(found).To(Equal(true), "cannot find project in the account team projects list")
}
})
It("AccountAuthentications check authentication methods", func() {
list, errL := client.AccountAuthentications.List(account.Account.Id)
Expect(errL).NotTo(HaveOccurred())
Expect(list.AuthenticationMethods).NotTo(BeEmpty(), "default auth methods should be created automatically")
})
It("AccountAuthentications add new one", func() {
resp, errL := client.AccountAuthentications.Create(account.Account.Id, AccountAuthenticationMethod{
Name: "test-auth",
Type: "saml",
})
Expect(errL).NotTo(HaveOccurred())
Expect(resp.AuthenticationMethod.Id).NotTo(BeEmpty())
Expect(resp.AuthenticationMethod.SAMLMetadataUrl).NotTo(BeEmpty())
Expect(resp.AuthenticationMethod.SAMLAcsUrl).NotTo(BeEmpty())
Expect(resp.AuthenticationMethod.AccountId).To(Equal(account.Account.Id))
Expect(resp.APIResponse.Message).To(BeEmpty())
Expect(resp.APIResponse.Errors).To(BeEmpty())
})
It("remove all the stuff", func() {
if errD := client.AccountTeamProjects.Delete(account.Account.Id, team.Team.Id, projectName); errD != nil {
Fail("cannot delete account team project association :" + errD.Error())
}
if errD := client.Projects.Delete(projectName); errD != nil {
Fail("cannot delete project :" + errD.Error())
}
if list, errL := client.AccountTeamMembers.List(account.Account.Id, team.Team.Id); errL != nil {
Fail("cannot get a list of account team members:" + errL.Error())
} else {
for _, m := range list.Members {
if errD := client.AccountTeamMembers.Delete(account.Account.Id, team.Team.Id, m.UserEmail); errD != nil {
Fail("cannot delete account team member:" + errD.Error())
}
}
}
if errD := client.AccountTeams.Delete(account.Account.Id, team.Team.Id); errD != nil {
Fail("cannot delete account team :" + errD.Error())
}
if errD := client.Accounts.Delete(account.Account.Id); errD != nil {
Fail("cannot delete account :" + errD.Error())
}
})
})
})