Skip to content

Commit b54d8bd

Browse files
Merge pull request #135 from opsgenie/add-escalation-schedule-in-responder-type-in-alert-policy
* add Escalation & Schedule responder type in alert policies --------- Co-authored-by: Jan Horstmann <[email protected]>
2 parents 121d2e9 + ba3b819 commit b54d8bd

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

policy/policy_test.go

+46-2
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ func TestCreateAlertPolicy_Validate(t *testing.T) {
126126

127127
req.Responders = &[]alert.Responder{
128128
{
129-
Type: alert.ScheduleResponder,
129+
Type: "",
130130
Name: "",
131131
Id: "",
132132
Username: "",
133133
},
134134
}
135135
err = req.Validate()
136-
assert.Equal(t, err.Error(), errors.New("responder type for alert policy should be one of team or user").Error())
136+
assert.Equal(t, err.Error(), errors.New("responder type for alert policy should be one of team, user, escalation or schedule").Error())
137137

138138
req.Responders = &[]alert.Responder{
139139
{
@@ -179,6 +179,50 @@ func TestCreateAlertPolicy_Validate(t *testing.T) {
179179
err = req.Validate()
180180
assert.Nil(t, err)
181181

182+
req.Responders = &[]alert.Responder{
183+
{
184+
Type: alert.EscalationResponder,
185+
Name: "",
186+
Id: "",
187+
Username: "user1",
188+
},
189+
}
190+
err = req.Validate()
191+
assert.Equal(t, err.Error(), errors.New("responder id should be provided").Error())
192+
193+
req.Responders = &[]alert.Responder{
194+
{
195+
Type: alert.EscalationResponder,
196+
Name: "",
197+
Id: "teamId",
198+
Username: "",
199+
},
200+
}
201+
err = req.Validate()
202+
assert.Nil(t, err)
203+
204+
req.Responders = &[]alert.Responder{
205+
{
206+
Type: alert.ScheduleResponder,
207+
Name: "",
208+
Id: "",
209+
Username: "user1",
210+
},
211+
}
212+
err = req.Validate()
213+
assert.Equal(t, err.Error(), errors.New("responder id should be provided").Error())
214+
215+
req.Responders = &[]alert.Responder{
216+
{
217+
Type: alert.ScheduleResponder,
218+
Name: "",
219+
Id: "teamId",
220+
Username: "",
221+
},
222+
}
223+
err = req.Validate()
224+
assert.Nil(t, err)
225+
182226
req.Priority = "asd"
183227
err = req.Validate()
184228
assert.Equal(t, err.Error(), errors.New("Priority should be one of these: 'P1', 'P2', 'P3', 'P4' and 'P5'").Error())

policy/request.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ func ValidateDelayAction(action DelayAction) error {
681681

682682
func ValidateResponders(responders *[]alert.Responder) error {
683683
for _, responder := range *responders {
684-
if responder.Type != alert.UserResponder && responder.Type != alert.TeamResponder {
685-
return errors.New("responder type for alert policy should be one of team or user")
684+
if responder.Type != alert.UserResponder && responder.Type != alert.TeamResponder && responder.Type != alert.EscalationResponder && responder.Type != alert.ScheduleResponder {
685+
return errors.New("responder type for alert policy should be one of team, user, escalation or schedule")
686686
}
687687
if responder.Id == "" {
688688
return errors.New("responder id should be provided")

0 commit comments

Comments
 (0)