forked from OpsLevel/opslevel-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration_test.go
221 lines (208 loc) · 9.2 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
package opslevel_test
import (
"testing"
"github.com/opslevel/opslevel-go/v2023"
"github.com/rocktavious/autopilot/v2023"
)
func TestCreateAWSIntegration(t *testing.T) {
// Arrange
testRequest := NewTestRequest(
`"mutation AWSIntegrationCreate($input:AwsIntegrationInput!){awsIntegrationCreate(input: $input){integration{id,name,type,createdAt,installedAt,... on AwsIntegration{iamRole,externalId,awsTagsOverrideOwnership,ownershipTagKeys},... on NewRelicIntegration{baseUrl,accountKey}},errors{message,path}}}"`,
`{"input": { "iamRole": "arn:aws:iam::XXXX:role/aws-integration-role", "externalId": "123456789", "ownershipTagKeys": ["owner"] }}`,
`{"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"
]
},
"errors": []
}}}`,
)
client := BestTestClient(t, "integration/create_aws", testRequest)
// Act
result, err := client.CreateIntegrationAWS(opslevel.AWSIntegrationInput{
IAMRole: opslevel.NewString("arn:aws:iam::XXXX:role/aws-integration-role"),
ExternalID: opslevel.NewString("123456789"),
})
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "AWS - XXXX", result.Name)
}
func TestCreateNewRelicIntegration(t *testing.T) {
// Arrange
testRequest := NewTestRequest(
`"mutation NewRelicIntegrationCreate($input:NewRelicIntegrationInput!){newRelicIntegrationCreate(input: $input){integration{id,name,type,createdAt,installedAt,... on AwsIntegration{iamRole,externalId,awsTagsOverrideOwnership,ownershipTagKeys},... on NewRelicIntegration{baseUrl,accountKey}},errors{message,path}}}"`,
`{ "input": { "apiKey": "123456789", "baseUrl": "https://api.newrelic.com/graphql", "accountKey": "XXXX" }}`,
`{"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.NewString("123456789"),
BaseUrl: opslevel.NewString("https://api.newrelic.com/graphql"),
AccountKey: opslevel.NewString("XXXX"),
})
// 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 := NewTestRequest(
`"query IntegrationGet($id:ID!){account{integration(id: $id){id,name,type,createdAt,installedAt,... on AwsIntegration{iamRole,externalId,awsTagsOverrideOwnership,ownershipTagKeys},... on NewRelicIntegration{baseUrl,accountKey}}}}"`,
`{ {{ 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 TestGetMissingIntegraion(t *testing.T) {
// Arrange
testRequest := NewTestRequest(
`"query IntegrationGet($id:ID!){account{integration(id: $id){id,name,type,createdAt,installedAt,... on AwsIntegration{iamRole,externalId,awsTagsOverrideOwnership,ownershipTagKeys},... on NewRelicIntegration{baseUrl,accountKey}}}}"`,
`{ {{ 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 := NewTestRequest(
`"query IntegrationList($after:String!$first:Int!){account{integrations(after: $after, first: $first){nodes{id,name,type,createdAt,installedAt,... on AwsIntegration{iamRole,externalId,awsTagsOverrideOwnership,ownershipTagKeys},... on NewRelicIntegration{baseUrl,accountKey}},{{ template "pagination_request" }},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 := NewTestRequest(
`"query IntegrationList($after:String!$first:Int!){account{integrations(after: $after, first: $first){nodes{id,name,type,createdAt,installedAt,... on AwsIntegration{iamRole,externalId,awsTagsOverrideOwnership,ownershipTagKeys},... on NewRelicIntegration{baseUrl,accountKey}},{{ template "pagination_request" }},totalCount}}}"`,
`{{ template "pagination_second_query_variables" }}`,
`{ "data": { "account": { "integrations": { "nodes": [ { {{ template "kubernetes_integration_response" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}`,
)
requests := []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 := NewTestRequest(
`"mutation AWSIntegrationUpdate($input:AwsIntegrationInput!$integration:IdentifierInput!){awsIntegrationUpdate(integration: $integration input: $input){integration{id,name,type,createdAt,installedAt,... on AwsIntegration{iamRole,externalId,awsTagsOverrideOwnership,ownershipTagKeys},... on NewRelicIntegration{baseUrl,accountKey}},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.NewString("Dev2"),
ExternalID: opslevel.NewString("123456789"),
})
// Assert
autopilot.Equals(t, nil, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "Dev2", result.Name)
}
func TestUpdateNewRelicIntegration(t *testing.T) {
// Arrange
testRequest := NewTestRequest(
`"mutation NewRelicIntegrationUpdate($input:NewRelicIntegrationInput!$resource:IdentifierInput!){newRelicIntegrationUpdate(input: $input resource: $resource){integration{id,name,type,createdAt,installedAt,... on AwsIntegration{iamRole,externalId,awsTagsOverrideOwnership,ownershipTagKeys},... on NewRelicIntegration{baseUrl,accountKey}},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.NewString("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 := 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)
}