@@ -35,6 +35,8 @@ const (
3535
3636 testID = "fake-id"
3737
38+ testID2 = "fake-id-2"
39+
3840 testRegion = "fake-region"
3941
4042 testIntegrationType = "PAGER_DUTY"
@@ -79,12 +81,14 @@ func TestIntegrationsCreate(t *testing.T) {
7981 },
8082 },
8183 api : testCreateIntegrationAPI (
82- & admin.ThirdPartyIntegration {
83- Id : pointer .MakePtr (string (testID )),
84- Type : pointer .MakePtr ("DATADOG" ),
85- ApiKey : pointer .MakePtr (testAPIKey ),
86- Region : pointer .MakePtr (string (testRegion )),
87- SendCollectionLatencyMetrics : pointer .MakePtr (true ),
84+ []admin.ThirdPartyIntegration {
85+ {
86+ Id : pointer .MakePtr (string (testID )),
87+ Type : pointer .MakePtr ("DATADOG" ),
88+ ApiKey : pointer .MakePtr (testAPIKey ),
89+ Region : pointer .MakePtr (string (testRegion )),
90+ SendCollectionLatencyMetrics : pointer .MakePtr (true ),
91+ },
8892 },
8993 nil ,
9094 ),
@@ -163,18 +167,106 @@ func TestIntegrationsCreate(t *testing.T) {
163167 },
164168 },
165169 api : testCreateIntegrationAPI (
166- & admin.ThirdPartyIntegration {
167- Id : pointer .MakePtr (string (testID )),
168- Type : pointer .MakePtr ("BLAH" ),
169- ApiKey : pointer .MakePtr (testAPIKey ),
170- Region : pointer .MakePtr (string (testRegion )),
171- SendCollectionLatencyMetrics : pointer .MakePtr (true ),
170+ []admin.ThirdPartyIntegration {
171+ {
172+ Id : pointer .MakePtr (string (testID )),
173+ Type : pointer .MakePtr ("BLAH" ),
174+ ApiKey : pointer .MakePtr (testAPIKey ),
175+ Region : pointer .MakePtr (string (testRegion )),
176+ SendCollectionLatencyMetrics : pointer .MakePtr (true ),
177+ },
172178 },
173179 nil ,
174180 ),
175181 expected : nil ,
176182 expectedError : integration .ErrUnsupportedIntegrationType ,
177183 },
184+
185+ {
186+ title : "failure to extract matching type from API reply" ,
187+ integration : & integration.ThirdPartyIntegration {
188+ AtlasThirdPartyIntegrationSpec : akov2.AtlasThirdPartyIntegrationSpec {
189+ Type : "DATADOG" ,
190+ Datadog : & akov2.DatadogIntegration {
191+ Region : testRegion ,
192+ SendCollectionLatencyMetrics : pointer .MakePtr ("enabled" ),
193+ SendDatabaseMetrics : pointer .MakePtr ("disabled" ),
194+ },
195+ },
196+ DatadogSecrets : & integration.DatadogSecrets {
197+ APIKey : testAPIKey ,
198+ },
199+ },
200+ api : testCreateIntegrationAPI (
201+ []admin.ThirdPartyIntegration {
202+ {
203+ Id : pointer .MakePtr (string (testID )),
204+ Type : pointer .MakePtr ("SLACK" ),
205+ ApiToken : pointer .MakePtr ("fake-token" ),
206+ ChannelName : pointer .MakePtr ("channel" ),
207+ TeamName : pointer .MakePtr ("team" ),
208+ },
209+ {
210+ Id : pointer .MakePtr (string (testID2 )),
211+ Type : pointer .MakePtr ("WEBHOOK" ),
212+ Url : pointer .MakePtr ("http://example.com/fake" ),
213+ },
214+ },
215+ nil ,
216+ ),
217+ expected : nil ,
218+ expectedError : integration .ErrNotFound ,
219+ },
220+
221+ {
222+ title : "extracts matching type from API reply" ,
223+ integration : & integration.ThirdPartyIntegration {
224+ AtlasThirdPartyIntegrationSpec : akov2.AtlasThirdPartyIntegrationSpec {
225+ Type : "DATADOG" ,
226+ Datadog : & akov2.DatadogIntegration {
227+ Region : testRegion ,
228+ SendCollectionLatencyMetrics : pointer .MakePtr ("enabled" ),
229+ SendDatabaseMetrics : pointer .MakePtr ("disabled" ),
230+ },
231+ },
232+ DatadogSecrets : & integration.DatadogSecrets {
233+ APIKey : testAPIKey ,
234+ },
235+ },
236+ api : testCreateIntegrationAPI (
237+ []admin.ThirdPartyIntegration {
238+ {
239+ Id : pointer .MakePtr (string (testID )),
240+ Type : pointer .MakePtr ("SLACK" ),
241+ ApiToken : pointer .MakePtr ("fake-token" ),
242+ ChannelName : pointer .MakePtr ("channel" ),
243+ TeamName : pointer .MakePtr ("team" ),
244+ },
245+ {
246+ Id : pointer .MakePtr (string (testID2 )),
247+ Type : pointer .MakePtr ("DATADOG" ),
248+ SendCollectionLatencyMetrics : pointer .MakePtr (false ),
249+ SendDatabaseMetrics : pointer .MakePtr (true ),
250+ ApiKey : pointer .MakePtr (testAPIKey ),
251+ },
252+ },
253+ nil ,
254+ ),
255+ expected : & integration.ThirdPartyIntegration {
256+ ID : testID2 ,
257+ AtlasThirdPartyIntegrationSpec : akov2.AtlasThirdPartyIntegrationSpec {
258+ Type : "DATADOG" ,
259+ Datadog : & akov2.DatadogIntegration {
260+ SendCollectionLatencyMetrics : pointer .MakePtr ("disabled" ),
261+ SendDatabaseMetrics : pointer .MakePtr ("enabled" ),
262+ },
263+ },
264+ DatadogSecrets : & integration.DatadogSecrets {
265+ APIKey : testAPIKey ,
266+ },
267+ },
268+ expectedError : nil ,
269+ },
178270 } {
179271 ctx := context .Background ()
180272 t .Run (tc .title , func (t * testing.T ) {
@@ -410,19 +502,15 @@ func TestIntegrationDelete(t *testing.T) {
410502 }
411503}
412504
413- func testCreateIntegrationAPI (integration * admin.ThirdPartyIntegration , err error ) admin.ThirdPartyIntegrationsApi {
505+ func testCreateIntegrationAPI (integrations [] admin.ThirdPartyIntegration , err error ) admin.ThirdPartyIntegrationsApi {
414506 var apiMock mockadmin.ThirdPartyIntegrationsApi
415507
416508 apiMock .EXPECT ().CreateThirdPartyIntegration (
417509 mock .Anything , mock .Anything , testProjectID , mock .Anything ,
418510 ).Return (admin.CreateThirdPartyIntegrationApiRequest {ApiService : & apiMock })
419511
420512 paginatedIntegration := & admin.PaginatedIntegration {}
421- if integration != nil {
422- paginatedIntegration .Results = & []admin.ThirdPartyIntegration {
423- * integration ,
424- }
425- }
513+ paginatedIntegration .Results = & integrations
426514 apiMock .EXPECT ().CreateThirdPartyIntegrationExecute (
427515 mock .AnythingOfType ("admin.CreateThirdPartyIntegrationApiRequest" ),
428516 ).Return (paginatedIntegration , nil , err )
0 commit comments