forked from OpsLevel/opslevel-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup_test.go
320 lines (298 loc) · 18.1 KB
/
group_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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
package opslevel_test
import (
"testing"
ol "github.com/opslevel/opslevel-go/v2023"
"github.com/rocktavious/autopilot/v2023"
)
// TODO: not sure if there is a better way to handle reusing a client
// Probably should be a feature of autopilot
var getGroupWithAliasClient *ol.Client
func getGroupWithAliasTestClient(t *testing.T) *ol.Client {
if getGroupWithAliasClient == nil {
getGroupWithAliasClient = ATestClientAlt(t, "group/get", "group/get_with_alias")
}
return getGroupWithAliasClient
}
func TestDeleteGroup(t *testing.T) {
// Arrange
testRequest := NewTestRequest(
`"mutation GroupDelete($input:IdentifierInput!){groupDelete(resource: $input){errors{message,path}}}"`,
`{"input": { {{ template "id2" }} }}`,
`{"data": {"groupDelete": {"errors": [] }}}`,
)
client := BestTestClient(t, "group/delete", testRequest)
// Act
err := client.DeleteGroup(string(id2))
// Assert
autopilot.Ok(t, err)
}
func TestDeleteGroupWithAlias(t *testing.T) {
// Arrange
testRequest := NewTestRequest(
`"mutation GroupDelete($input:IdentifierInput!){groupDelete(resource: $input){errors{message,path}}}"`,
`{"input": {"alias": "platform"}}`,
`{"data": {"groupDelete": {"errors": [] }}}`,
)
client := BestTestClient(t, "group/delete_with_alias", testRequest)
// client := ATestClientAlt(t, "group/delete", "group/delete_with_alias")
// Act
err := client.DeleteGroup("platform")
// Assert
autopilot.Ok(t, err)
}
func TestChildTeams(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query GroupChildTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){childTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},memberships{nodes{team{alias,id},role,user{id,email}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}"`,
`{ {{ template "first_page_variables" }}, "group": "123456789" }`,
`{ "data": { "account": { "group": { "childTeams": { "nodes": [ {{ template "team_1" }}, {{ template "team_2" }} ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}}`,
)
testRequestTwo := NewTestRequest(
`"query GroupChildTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){childTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},memberships{nodes{team{alias,id},role,user{id,email}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}"`,
`{ {{ template "second_page_variables" }}, "group": "123456789" }`,
`{ "data": { "account": { "group": { "childTeams": { "nodes": [ {{ template "team_3" }} ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
requests := []TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "group/child_teams", requests...)
group := ol.Group{
GroupId: ol.GroupId{
Id: "123456789",
},
}
// Act
resp, err := group.ChildTeams(client, nil)
result := resp.Nodes
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 3, resp.TotalCount)
autopilot.Equals(t, "example", result[0].Alias)
autopilot.Equals(t, "example_3", result[2].Alias)
}
func TestDescendantTeams(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query GroupDescendantTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount},memberships{nodes{team{alias,id},role,user{id,email}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
`{ {{ template "first_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "descendantTeams": { "nodes": [ {{ template "team_1" }}, {{ template "team_2" }} ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}}`,
)
testRequestTwo := NewTestRequest(
`"query GroupDescendantTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount},memberships{nodes{team{alias,id},role,user{id,email}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
`{ {{ template "second_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "descendantTeams": { "nodes": [ {{ template "team_3" }} ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
requests := []TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "group/descendant_teams", requests...)
// Act
group := ol.Group{
GroupId: ol.GroupId{
Id: id4,
},
}
resp, err := group.DescendantTeams(client, nil)
result := resp.Nodes
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 3, resp.TotalCount)
autopilot.Equals(t, "example", result[0].Alias)
autopilot.Equals(t, "example_3", result[2].Alias)
}
func TestDescendantRepositories(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query GroupDescendantRepositoriesList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantRepositories(after: $after, first: $first){hiddenCount,nodes{archivedAt,createdOn,defaultAlias,defaultBranch,description,forked,htmlUrl,id,languages{name,usage},lastOwnerChangedAt,name,organization,owner{alias,id},private,repoKey,services{edges{atRoot,node{id,aliases},paths{href,path},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},{{ template "pagination_request" }},totalCount},tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount},tier{alias,description,id,index,name},type,url,visible},organizationCount,ownedCount,{{ template "pagination_request" }},totalCount,visibleCount}}}}"`,
`{ {{ template "first_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "descendantRepositories": { "nodes": [ {{ template "repository_1"}} ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
testRequestTwo := NewTestRequest(
`"query GroupDescendantRepositoriesList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantRepositories(after: $after, first: $first){hiddenCount,nodes{archivedAt,createdOn,defaultAlias,defaultBranch,description,forked,htmlUrl,id,languages{name,usage},lastOwnerChangedAt,name,organization,owner{alias,id},private,repoKey,services{edges{atRoot,node{id,aliases},paths{href,path},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},{{ template "pagination_request" }},totalCount},tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount},tier{alias,description,id,index,name},type,url,visible},organizationCount,ownedCount,{{ template "pagination_request" }},totalCount,visibleCount}}}}"`,
`{ {{ template "second_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "descendantRepositories": { "nodes": [ {{ template "repository_2" }} ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 } }}}}`,
)
requests := []TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "group/descendant_repositories", requests...)
// Act
group := ol.Group{
GroupId: ol.GroupId{
Id: id4,
},
}
resp, err := group.DescendantRepositories(client, nil)
result := resp.Nodes
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 2, resp.TotalCount)
autopilot.Equals(t, "github.com:rocktavious/autopilot", result[0].DefaultAlias)
autopilot.Equals(t, "github.com:OpsLevel/cli", result[1].DefaultAlias)
}
func TestDescendantServices(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query GroupDescendantServicesList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantServices(after: $after, first: $first){nodes{apiDocumentPath,description,framework,htmlUrl,id,aliases,language,lifecycle{alias,description,id,index,name},managedAliases,name,owner{alias,id},preferredApiDocument{id,htmlUrl,source{... on ApiDocIntegration{id,name,type},... on ServiceRepository{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},timestamps{createdAt,updatedAt}},preferredApiDocumentSource,product,repos{edges{node{id,defaultAlias},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},{{ template "pagination_request" }},totalCount},tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount},tier{alias,description,id,index,name},timestamps{createdAt,updatedAt},tools{nodes{category,categoryAlias,displayName,environment,id,url,service{id,aliases}},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
`{ {{ template "first_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "descendantServices": { "nodes": [ {{ template "service_1"}} ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
testRequestTwo := NewTestRequest(
`"query GroupDescendantServicesList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantServices(after: $after, first: $first){nodes{apiDocumentPath,description,framework,htmlUrl,id,aliases,language,lifecycle{alias,description,id,index,name},managedAliases,name,owner{alias,id},preferredApiDocument{id,htmlUrl,source{... on ApiDocIntegration{id,name,type},... on ServiceRepository{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},timestamps{createdAt,updatedAt}},preferredApiDocumentSource,product,repos{edges{node{id,defaultAlias},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},{{ template "pagination_request" }},totalCount},tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount},tier{alias,description,id,index,name},timestamps{createdAt,updatedAt},tools{nodes{category,categoryAlias,displayName,environment,id,url,service{id,aliases}},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
`{ {{ template "second_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "descendantServices": { "nodes": [ {{ template "service_2" }} ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
requests := []TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "group/descendant_services", requests...)
// Act
group := ol.Group{
GroupId: ol.GroupId{
Id: id4,
},
}
resp, err := group.DescendantServices(client, nil)
result := resp.Nodes
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 2, resp.TotalCount)
autopilot.Equals(t, "example", result[0].Aliases[0])
autopilot.Equals(t, "example_2", result[1].Aliases[0])
}
func TestDescendantSubgroups(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query GroupDescendantSubgroupsList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantSubgroups(after: $after, first: $first){nodes{alias,id,description,htmlUrl,name,parent{alias,id}},{{ template "pagination_request" }},totalCount}}}}"`,
`{ {{ template "first_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "descendantSubgroups": { "nodes": [ {{ template "group_1"}} ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
testRequestTwo := NewTestRequest(
`"query GroupDescendantSubgroupsList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantSubgroups(after: $after, first: $first){nodes{alias,id,description,htmlUrl,name,parent{alias,id}},{{ template "pagination_request" }},totalCount}}}}"`,
`{ {{ template "second_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "descendantSubgroups": { "nodes": [ {{ template "group_2" }} ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
requests := []TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "group/descendant_subgroups", requests...)
// Act
group := ol.Group{
GroupId: ol.GroupId{
Id: id4,
},
}
resp, err := group.DescendantSubgroups(client, nil)
result := resp.Nodes
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 2, resp.TotalCount)
autopilot.Equals(t, "test_group_1", result[0].Alias)
autopilot.Equals(t, "test_group_2", result[1].Alias)
}
func TestGetGroup(t *testing.T) {
// Arrange
client := ATestClient(t, "group/get")
// Act
result, err := client.GetGroup(id4)
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, "test_group_1", result.Alias)
autopilot.Equals(t, "", string(result.Parent.Id))
}
func TestGetGroupWithAlias(t *testing.T) {
// Arrange
client := getGroupWithAliasTestClient(t)
// Act
result, err := client.GetGroupWithAlias("test_group_1")
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, "test_group_1", result.Alias)
autopilot.Equals(t, "", string(result.Parent.Id))
}
func TestListGroups(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query ($after:String!$first:Int!){account{groups(after: $after, first: $first){nodes{alias,id,description,htmlUrl,name,parent{alias,id}},{{ template "pagination_request" }},totalCount}}}"`,
`{{ template "pagination_initial_query_variables" }}`,
`{ "data": {
"account": {
"groups": {
"nodes": [
{
"alias": "test_group_2",
{{ template "id2" }},
"description": "test1123",
"htmlUrl": "https://app.opslevel-staging.com/groups/test_group_2",
"name": "test_group_2",
"parent": {
"alias": "test_group_1",
{{ template "id4" }}
}
},
{
"alias": "test_group_1",
{{ template "id4" }},
"description": null,
"htmlUrl": "https://app.opslevel-staging.com/groups/test_group_1",
"name": "test_group_1",
"parent": null
}
],
{{ template "pagination_initial_pageInfo_response" }},
"totalCount": 2
}}}}`,
)
testRequestTwo := NewTestRequest(
`"query ($after:String!$first:Int!){account{groups(after: $after, first: $first){nodes{alias,id,description,htmlUrl,name,parent{alias,id}},{{ template "pagination_request" }},totalCount}}}"`,
`{{ template "pagination_second_query_variables" }}`,
`{"data": {
"account": {
"groups": {
"nodes": [
{
"alias": "test_group_3",
{{ template "id3" }},
"description": "third test group",
"htmlUrl": "https://app.opslevel-staging.com/groups/test_group_3",
"name": "test_group_3",
"parent": {
"alias": "test_group_1",
{{ template "id4" }}
}
}
],
{{ template "pagination_second_pageInfo_response" }},
"totalCount": 1
}}}}`,
)
requests := []TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "group/list", requests...)
// Act
response, err := client.ListGroups(nil)
result := response.Nodes
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 3, response.TotalCount)
autopilot.Equals(t, "test_group_2", result[0].Alias)
autopilot.Equals(t, "test_group_1", result[1].Alias)
autopilot.Equals(t, "test_group_3", result[2].Alias)
}
func TestMembers(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query GroupMembersList($after:String!$first:Int!$group:ID!){account{group(id: $group){members(after: $after, first: $first){nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount}}}}"`,
`{ {{ template "first_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "members": { "nodes": [ {{ template "user_1"}}, {{ template "user_2"}} ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 } }}}}`,
)
testRequestTwo := NewTestRequest(
`"query GroupMembersList($after:String!$first:Int!$group:ID!){account{group(id: $group){members(after: $after, first: $first){nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount}}}}"`,
`{ {{ template "second_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "members": { "nodes": [ {{ template "user_3"}} ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 } }}}}`,
)
requests := []TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "group/members", requests...)
// Act
group := ol.Group{
GroupId: ol.GroupId{
Id: id4,
},
}
resp, err := group.Members(client, nil)
result := resp.Nodes
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 3, resp.TotalCount)
autopilot.Equals(t, "[email protected]", result[0].Email)
autopilot.Equals(t, "Matthew Brahms", result[2].Name)
}