-
Notifications
You must be signed in to change notification settings - Fork 13
/
integration_test.go
431 lines (412 loc) · 18.5 KB
/
integration_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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
package opslevel_test
import (
"testing"
"github.com/opslevel/opslevel-go/v2024"
"github.com/rocktavious/autopilot/v2023"
)
func TestCreateAWSIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation AWSIntegrationCreate($input:AwsIntegrationInput!){awsIntegrationCreate(input: $input){integration{{ template "integration_request" }},errors{message,path}}}`,
`{"input": { "iamRole": "arn:aws:iam::XXXX:role/aws-integration-role", "externalId": "123456789", "ownershipTagKeys": ["owner"], "regionOverride": ["us-east-1"] }}`,
`{"data": {
"awsIntegrationCreate": {
"integration": {
{{ template "id1" }},
"name": "AWS - XXXX",
"type": "aws",
"createdAt": "2023-04-26T16:25:29.574450Z",
"installedAt": "2023-04-26T16:25:28.541124Z",
"iamRole": "arn:aws:iam::XXXX:role/aws-integration-role",
"externalId": "123456789",
"awsTagsOverrideOwnership": true,
"ownershipTagKeys": [
"owner"
],
"regionOverride": [
"us-east-1"
]
},
"errors": []
}}}`,
)
client := BestTestClient(t, "integration/create_aws", testRequest)
// Act
result, err := client.CreateIntegrationAWS(opslevel.AWSIntegrationInput{
IAMRole: opslevel.RefOf("arn:aws:iam::XXXX:role/aws-integration-role"),
ExternalID: opslevel.RefOf("123456789"),
RegionOverride: opslevel.RefOf([]string{"us-east-1"}),
})
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, []string{"us-east-1"}, result.RegionOverride)
autopilot.Equals(t, "AWS - XXXX", result.Name)
}
func TestCreateAzureResourcesIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation AzureResourcesIntegrationCreate($input:AzureResourcesIntegrationInput!){azureResourcesIntegrationCreate(input: $input){integration{{ template "integration_request" }},errors{message,path}}}`,
`{"input": { "name": "new azure resources", "tenantId": "12345678-1234-1234-1234-123456789abc", "subscriptionId": "12345678-1234-1234-1234-123456789def", "clientId": "XXX_client_id_XXX", "clientSecret": "XXX_client_secret_XXX"}}`,
`{"data": {
"azureResourcesIntegrationCreate": {
"integration": {
{{ template "id1" }},
"name": "new azure resources",
"type": "azureResources",
"createdAt": "2024-07-04T16:25:29.574450Z",
"installedAt": "2024-07-04T16:25:28.541124Z",
"tenantId": "12345678-1234-1234-1234-123456789abc",
"subscriptionId": "12345678-1234-1234-1234-123456789def",
"aliases": ["new_azure_resources"]
},
"errors": []
}}}`,
)
client := BestTestClient(t, "integration/create_azure_resources", testRequest)
// Act
result, err := client.CreateIntegrationAzureResources(opslevel.AzureResourcesIntegrationInput{
Name: opslevel.RefOf("new azure resources"),
TenantId: opslevel.RefOf("12345678-1234-1234-1234-123456789abc"),
SubscriptionId: opslevel.RefOf("12345678-1234-1234-1234-123456789def"),
ClientId: opslevel.RefOf("XXX_client_id_XXX"),
ClientSecret: opslevel.RefOf("XXX_client_secret_XXX"),
})
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "new azure resources", result.Name)
autopilot.Equals(t, "12345678-1234-1234-1234-123456789abc", result.TenantId)
autopilot.Equals(t, "12345678-1234-1234-1234-123456789def", result.SubscriptionId)
autopilot.Equals(t, []string{"new_azure_resources"}, result.AzureResourcesIntegrationFragment.Aliases)
}
func TestCreateEventIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation EventIntegrationCreate($input:EventIntegrationInput!){eventIntegrationCreate(input: $input){integration{{ template "integration_request" }},errors{message,path}}}`,
`{"input": { "name": "Custom Event", "type": "deploy" }}`,
`{"data": {
"eventIntegrationCreate": {
"integration": {
{{ template "id1" }},
"name": "Custom Event",
"type": "deploy",
"createdAt": "2023-04-26T16:25:29.574450Z",
"installedAt": "2023-04-26T16:25:28.541124Z"
},
"errors": []
}}}`,
)
client := BestTestClient(t, "integration/create_event", testRequest)
// Act
result, err := client.CreateEventIntegration(opslevel.EventIntegrationInput{
Name: opslevel.RefOf("Custom Event"),
Type: opslevel.EventIntegrationEnumDeploy,
})
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "Custom Event", result.Name)
}
func TestCreateGoogleCloudIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation GoogleCloudIntegrationCreate($input:GoogleCloudIntegrationInput!){googleCloudIntegrationCreate(input: $input){integration{{ template "integration_request" }},errors{message,path}}}`,
`{"input": { "name": "new gcp integration", "ownershipTagKeys": ["owner", "team", "opslevel_team"], "privateKey": "XXX_PRIVATE_KEY_XXX", "clientEmail": "helloworld@appspot.gserviceaccount.com", "tagsOverrideOwnership": true }}`,
`{"data": {
"googleCloudIntegrationCreate": {
"integration": {
{{ template "id1" }},
"name": "new gcp integration",
"type": "googleCloud",
"createdAt": "2024-07-04T16:25:29.574450Z",
"installedAt": "2024-07-04T16:25:28.541124Z",
"ownershipTagKeys": ["owner", "team", "opslevel_team"],
"projects": [{"id": "123", "name": "my-project-1", "url": "XXX_URL_XXX"}],
"aliases": ["new_gcp_integration"],
"clientEmail": "helloworld@appspot.gserviceaccount.com",
"tagsOverrideOwnership": true
},
"errors": []
}}}`,
)
client := BestTestClient(t, "integration/create_gcp", testRequest)
// Act
result, err := client.CreateIntegrationGCP(opslevel.GoogleCloudIntegrationInput{
Name: opslevel.RefOf("new gcp integration"),
OwnershipTagKeys: opslevel.RefOf([]string{"owner", "team", "opslevel_team"}),
PrivateKey: opslevel.RefOf("XXX_PRIVATE_KEY_XXX"),
ClientEmail: opslevel.RefOf("helloworld@appspot.gserviceaccount.com"),
TagsOverrideOwnership: opslevel.RefOf(true),
})
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "new gcp integration", result.Name)
autopilot.Equals(t, "helloworld@appspot.gserviceaccount.com", result.ClientEmail)
autopilot.Equals(t, true, result.GoogleCloudIntegrationFragment.TagsOverrideOwnership)
autopilot.Equals(t, result.GoogleCloudIntegrationFragment.OwnershipTagKeys, []string{"owner", "team", "opslevel_team"})
autopilot.Equals(t, []string{"new_gcp_integration"}, result.GoogleCloudIntegrationFragment.Aliases)
autopilot.Equals(t, []opslevel.GoogleCloudProject{
{ID: "123", Name: "my-project-1", URL: "XXX_URL_XXX"},
}, result.Projects)
}
func TestCreateNewRelicIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation NewRelicIntegrationCreate($input:NewRelicIntegrationInput!){newRelicIntegrationCreate(input: $input){integration{{ template "integration_request" }},errors{message,path}}}`,
`{ "input": { "apiKey": "123456789", "baseUrl": "https://api.newrelic.com/graphql" }}`,
`{"data": {
"newRelicIntegrationCreate": {
"integration": {
{{ template "id1" }},
"name": "New Relic - XXXX",
"type": "new_relic",
"createdAt": "2023-04-26T16:25:29.574450Z",
"installedAt": "2023-04-26T16:25:28.541124Z",
"accountKey": "XXXX",
"baseUrl": "https://api.newrelic.com/graphql"
},
"errors": []
}}}`,
)
client := BestTestClient(t, "integration/create_new_relic", testRequest)
// Act
result, err := client.CreateIntegrationNewRelic(opslevel.NewRelicIntegrationInput{
ApiKey: opslevel.RefOf("123456789"),
BaseUrl: opslevel.RefOf("https://api.newrelic.com/graphql"),
})
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "New Relic - XXXX", result.Name)
}
func TestGetIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query IntegrationGet($id:ID!){account{integration(id: $id){{ template "integration_request" }}}}`,
`{ {{ template "id1" }} }`,
`{"data": {
"account": {
"integration": {
{{ template "id1" }},
"name": "Deploy",
"type": "deploy"
}
}}}`,
)
client := BestTestClient(t, "integration/get", testRequest)
// Act
result, err := client.GetIntegration(id1)
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "Deploy", result.Name)
}
func TestGetMissingIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query IntegrationGet($id:ID!){account{integration(id: $id){{ template "integration_request" }}}}`,
`{ {{ template "id2" }} }`,
`{"data": { "account": { "integration": null }}}`,
)
client := BestTestClient(t, "integration/get_missing", testRequest)
// Act
_, err := client.GetIntegration(id2)
// Assert
autopilot.Assert(t, err != nil, "This test should throw an error.")
}
func TestListIntegrations(t *testing.T) {
// Arrange
testRequestOne := autopilot.NewTestRequest(
`query IntegrationList($after:String!$first:Int!){account{integrations(after: $after, first: $first){nodes{{ template "integration_request" }},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}`,
`{{ template "pagination_initial_query_variables" }}`,
`{ "data": { "account": { "integrations": { "nodes": [ { {{ template "deploy_integration_response" }} }, { {{ template "payload_integration_response" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}`,
)
testRequestTwo := autopilot.NewTestRequest(
`query IntegrationList($after:String!$first:Int!){account{integrations(after: $after, first: $first){nodes{{ template "integration_request" }},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}`,
`{{ template "pagination_second_query_variables" }}`,
`{ "data": { "account": { "integrations": { "nodes": [ { {{ template "kubernetes_integration_response" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}`,
)
requests := []autopilot.TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "integration/list", requests...)
// Act
response, err := client.ListIntegrations(nil)
result := response.Nodes
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 3, response.TotalCount)
autopilot.Equals(t, "Payload", result[1].Name)
autopilot.Equals(t, "Kubernetes", result[2].Name)
}
func TestUpdateAWSIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation AWSIntegrationUpdate($input:AwsIntegrationInput!$integration:IdentifierInput!){awsIntegrationUpdate(integration: $integration input: $input){integration{{ template "integration_request" }},errors{message,path}}}`,
`{"integration": { {{ template "id1" }} }, "input": { "name": "Dev2", "externalId": "123456789", "ownershipTagKeys": null }}`,
`{"data": {
"awsIntegrationUpdate": {
"integration": {
{{ template "id1" }},
"name": "Dev2",
"type": "aws",
"createdAt": "2023-04-26T16:25:29.574450Z",
"installedAt": "2023-04-26T16:25:28.541124Z",
"iamRole": "arn:aws:iam::XXXX:role/aws-integration-role",
"externalId": "123456789",
"awsTagsOverrideOwnership": true,
"ownershipTagKeys": [
"owner"
]
},
"errors": []
}}}`,
)
client := BestTestClient(t, "integration/update_aws", testRequest)
// Act
result, err := client.UpdateIntegrationAWS(string(id1), opslevel.AWSIntegrationInput{
Name: opslevel.RefOf("Dev2"),
ExternalID: opslevel.RefOf("123456789"),
})
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "Dev2", result.Name)
}
func TestUpdateAzureResourcesIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation AzureResourcesIntegrationUpdate($input:AzureResourcesIntegrationInput!$integration:IdentifierInput!){azureResourcesIntegrationUpdate(integration: $integration input: $input){integration{{ template "integration_request" }},errors{message,path}}}`,
`{"integration": { {{ template "id1" }} }, "input": { "name": "updated azure resources", "clientId": "updated client id", "clientSecret": "updated client secret" }}`,
`{"data": {
"azureResourcesIntegrationUpdate": {
"integration": {
{{ template "id1" }},
"name": "updated azure resources",
"type": "azureResources",
"createdAt": "2024-07-04T16:25:29.574450Z",
"installedAt": "2024-07-04T16:25:28.541124Z",
"tenantId": "12345678-1234-1234-1234-123456789abc",
"subscriptionId": "12345678-1234-1234-1234-123456789def",
"aliases": ["alias1", "alias2"]
},
"errors": []
}}}`,
)
client := BestTestClient(t, "integration/update_azure_resources", testRequest)
// Act
result, err := client.UpdateIntegrationAzureResources(string(id1), opslevel.AzureResourcesIntegrationInput{
Name: opslevel.RefOf("updated azure resources"),
ClientId: opslevel.RefOf("updated client id"),
ClientSecret: opslevel.RefOf("updated client secret"),
})
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "updated azure resources", result.Name)
autopilot.Equals(t, "12345678-1234-1234-1234-123456789abc", result.TenantId)
autopilot.Equals(t, "12345678-1234-1234-1234-123456789def", result.SubscriptionId)
autopilot.Equals(t, []string{"alias1", "alias2"}, result.AzureResourcesIntegrationFragment.Aliases)
}
func TestUpdateGoogleCloudIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation GoogleCloudIntegrationUpdate($input:GoogleCloudIntegrationInput!$integration:IdentifierInput!){googleCloudIntegrationUpdate(integration: $integration input: $input){integration{{ template "integration_request" }},errors{message,path}}}`,
`{ "integration": { {{ template "id1" }} }, "input": { "name": "updated gcp", "ownershipTagKeys": ["team", "opslevel_team"], "privateKey": "XXX_PRIVATE_KEY_2_XXX", "clientEmail": "helloworld_2@appspot.gserviceaccount.com", "tagsOverrideOwnership": false }}`,
`{"data": {
"googleCloudIntegrationUpdate": {
"integration": {
{{ template "id1" }},
"name": "updated gcp",
"type": "googleCloud",
"createdAt": "2024-07-04T16:25:29.574450Z",
"installedAt": "2024-07-04T16:25:28.541124Z",
"ownershipTagKeys": ["team", "opslevel_team"],
"projects": [{"id": "123", "name": "my-project-1", "url": "XXX_URL_XXX"}],
"aliases": ["new_gcp_integration", "updated_gcp"],
"clientEmail": "helloworld_2@appspot.gserviceaccount.com",
"tagsOverrideOwnership": false
},
"errors": []
}}}`,
)
client := BestTestClient(t, "integration/update_gcp", testRequest)
// Act
result, err := client.UpdateIntegrationGCP(string(id1), opslevel.GoogleCloudIntegrationInput{
Name: opslevel.RefOf("updated gcp"),
OwnershipTagKeys: opslevel.RefOf([]string{"team", "opslevel_team"}),
PrivateKey: opslevel.RefOf("XXX_PRIVATE_KEY_2_XXX"),
ClientEmail: opslevel.RefOf("helloworld_2@appspot.gserviceaccount.com"),
TagsOverrideOwnership: opslevel.RefOf(false),
})
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "updated gcp", result.Name)
autopilot.Equals(t, "helloworld_2@appspot.gserviceaccount.com", result.ClientEmail)
autopilot.Equals(t, false, result.GoogleCloudIntegrationFragment.TagsOverrideOwnership)
autopilot.Equals(t, result.GoogleCloudIntegrationFragment.OwnershipTagKeys, []string{"team", "opslevel_team"})
autopilot.Equals(t, []string{"new_gcp_integration", "updated_gcp"}, result.GoogleCloudIntegrationFragment.Aliases)
autopilot.Equals(t, []opslevel.GoogleCloudProject{
{ID: "123", Name: "my-project-1", URL: "XXX_URL_XXX"},
}, result.Projects)
}
func TestUpdateNewRelicIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation NewRelicIntegrationUpdate($input:NewRelicIntegrationInput!$resource:IdentifierInput!){newRelicIntegrationUpdate(input: $input resource: $resource){integration{{ template "integration_request" }},errors{message,path}}}`,
`{"resource": { {{ template "id1" }} }, "input": { "baseUrl": "https://api-test.newrelic.com/graphql" }}`,
`{"data": {
"newRelicIntegrationUpdate": {
"integration": {
{{ template "id1" }},
"name": "New Relic - XXXX",
"type": "new_relic",
"createdAt": "2023-04-26T16:25:29.574450Z",
"installedAt": "2023-04-26T16:25:28.541124Z",
"accountKey": "XXXX",
"baseUrl": "https://api-test.newrelic.com/graphql"
},
"errors": []
}}}`,
)
client := BestTestClient(t, "integration/update_new_relic", testRequest)
// Act
result, err := client.UpdateIntegrationNewRelic(
string(id1),
opslevel.NewRelicIntegrationInput{
BaseUrl: opslevel.RefOf("https://api-test.newrelic.com/graphql"),
},
)
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "https://api-test.newrelic.com/graphql", result.BaseUrl)
}
func TestDeleteIntegration(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation IntegrationDelete($input:IdentifierInput!){integrationDelete(resource: $input){errors{message,path}}}`,
`{"input": { {{ template "id1" }} }}`,
`{"data": { "integrationDelete": { "errors": [] }}}`,
)
client := BestTestClient(t, "integration/delete", testRequest)
// Act
err := client.DeleteIntegration(string(id1))
// Assert
autopilot.Equals(t, nil, err)
}
func TestIntegrationReactivate(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation IntegrationReactivate($integration:IdentifierInput!){integrationReactivate(integration: $integration){integration{{ template "integration_request" }},errors{message,path}}}`,
`{"integration": { {{ template "id1" }} }}`,
`{"data": { "integrationReactivate": { "integration": { {{ template "id1" }} }, "errors": [] }}}`,
)
client := BestTestClient(t, "integration/reactivate", testRequest)
// Act
result, err := client.IntegrationReactivate(string(id1))
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
}