Skip to content

Commit

Permalink
add schedule responder type in policy
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunrajpal committed Jul 4, 2023
1 parent a797126 commit bed2246
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions alert/responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const (
TeamResponder ResponderType = "team"
EscalationResponder ResponderType = "escalation"
ScheduleResponder ResponderType = "schedule"
GroupResponder ResponderType = "group"
)

type Responder struct {
Expand Down
48 changes: 46 additions & 2 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ func TestCreateAlertPolicy_Validate(t *testing.T) {

req.Responders = &[]alert.Responder{
{
Type: alert.ScheduleResponder,
Type: alert.GroupResponder,
Name: "",
Id: "",
Username: "",
},
}
err = req.Validate()
assert.Equal(t, err.Error(), errors.New("responder type for alert policy should be one of team or user").Error())
assert.Equal(t, err.Error(), errors.New("responder type for alert policy should be one of team, user, escalation or schedule").Error())

req.Responders = &[]alert.Responder{
{
Expand Down Expand Up @@ -179,6 +179,50 @@ func TestCreateAlertPolicy_Validate(t *testing.T) {
err = req.Validate()
assert.Nil(t, err)

req.Responders = &[]alert.Responder{
{
Type: alert.EscalationResponder,
Name: "",
Id: "",
Username: "user1",
},
}
err = req.Validate()
assert.Equal(t, err.Error(), errors.New("responder id should be provided").Error())

req.Responders = &[]alert.Responder{
{
Type: alert.EscalationResponder,
Name: "",
Id: "teamId",
Username: "",
},
}
err = req.Validate()
assert.Nil(t, err)

req.Responders = &[]alert.Responder{
{
Type: alert.ScheduleResponder,
Name: "",
Id: "",
Username: "user1",
},
}
err = req.Validate()
assert.Equal(t, err.Error(), errors.New("responder id should be provided").Error())

req.Responders = &[]alert.Responder{
{
Type: alert.ScheduleResponder,
Name: "",
Id: "teamId",
Username: "",
},
}
err = req.Validate()
assert.Nil(t, err)

req.Priority = "asd"
err = req.Validate()
assert.Equal(t, err.Error(), errors.New("Priority should be one of these: 'P1', 'P2', 'P3', 'P4' and 'P5'").Error())
Expand Down
4 changes: 2 additions & 2 deletions policy/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ func ValidateDelayAction(action DelayAction) error {

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

0 comments on commit bed2246

Please sign in to comment.