-
Notifications
You must be signed in to change notification settings - Fork 13
/
alert_source_test.go
109 lines (100 loc) · 4.24 KB
/
alert_source_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
package opslevel_test
import (
"testing"
ol "github.com/opslevel/opslevel-go/v2024"
"github.com/rocktavious/autopilot/v2023"
)
func TestCreateAlertSourceService(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation AlertSourceServiceCreate($input:AlertSourceServiceCreateInput!){alertSourceServiceCreate(input: $input){alertSourceService{alertSource{description,externalId,id,integration{id,name,type},name,type,url},id,service{id,aliases},status},errors{message,path}}}`,
`{"input": { "alertSourceExternalIdentifier": { "externalId": "QWERTY", "type": "datadog" }, "service": { "alias": "example" }}}`,
`{"data": { "alertSourceServiceCreate": { "alertSourceService": { "service": { "aliases": ["example"] }}}}}`,
)
client := BestTestClient(t, "alert_source/create", testRequest)
// Act
result, _ := client.CreateAlertSourceService(ol.AlertSourceServiceCreateInput{
Service: *ol.NewIdentifier("example"),
AlertSourceExternalIdentifier: ol.NewAlertSource(ol.AlertSourceTypeEnumDatadog, "QWERTY"),
})
// Assert
autopilot.Equals(t, "example", result.Service.Aliases[0])
}
func TestGetAlertSourceWithExternalIdentifier(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query AlertSourceGet($externalIdentifier:AlertSourceExternalIdentifier!){account{alertSource(externalIdentifier: $externalIdentifier){description,externalId,id,integration{id,name,type},name,type,url}}}`,
`{"externalIdentifier": { "type": "datadog", "externalId": "12345678" }}`,
`{"data": {
"account": {
"alertSource": {
"description": "test",
"externalId": "12345678",
"id": "Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE",
"integration": {
"name": "test-integration",
"id": "Z2lkOi8vb3BzbGV2ZWwvSW50ZWdyYXRpb25zOjpQYWdlcmR1dHlJbnRlZ3JhdGlvbi8zMg",
"type": "datadog"
},
"name": "Example",
"type": "datadog",
"url": "https://example.com"
}
}}}`,
)
client := BestTestClient(t, "alert_source/get_with_external_identifier", testRequest)
// Act
result, err := client.GetAlertSourceWithExternalIdentifier(ol.AlertSourceExternalIdentifier{
Type: ol.AlertSourceTypeEnumDatadog,
ExternalId: "12345678",
})
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, "Example", result.Name)
autopilot.Equals(t, "test", result.Description)
autopilot.Equals(t, ol.AlertSourceTypeEnumDatadog, result.Type)
}
func TestGetAlertSource(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query AlertSourceGet($id:ID!){account{alertSource(id: $id){description,externalId,id,integration{id,name,type},name,type,url}}}`,
`{"id": "Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE" }`,
`{"data": {
"account": {
"alertSource": {
"description": "test",
"externalId": "12345678",
"id": "Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE",
"integration": {
"name": "test-integration",
"id": "Z2lkOi8vb3BzbGV2ZWwvSW50ZWdyYXRpb25zOjpQYWdlcmR1dHlJbnRlZ3JhdGlvbi8zMg",
"type": "datadog"
},
"name": "Example",
"type": "datadog",
"url": "https://example.com"
}
}}}`,
)
client := BestTestClient(t, "alert_source/get", testRequest)
// Act
result, err := client.GetAlertSource("Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE")
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, "Example", result.Name)
autopilot.Equals(t, "test", result.Description)
autopilot.Equals(t, ol.AlertSourceTypeEnumDatadog, result.Type)
}
func TestDeleteAlertSourceService(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation AlertSourceServiceDelete($input:AlertSourceDeleteInput!){alertSourceServiceDelete(input: $input){errors{message,path}}}`,
`{"input": { "id": "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvODYz" }}`,
`{"data": { "alertSourceServiceDelete": { "errors": [] }}}`,
)
client := BestTestClient(t, "alert_source/delete", testRequest)
// Act
err := client.DeleteAlertSourceService("Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvODYz")
// Assert
autopilot.Equals(t, nil, err)
}