@ -13,30 +13,61 @@ import (
func TestShouldSendAlertNotification ( t * testing . T ) {
tcs := [ ] struct {
name string
prevState m . AlertStateType
newState m . AlertStateType
expected bool
sendReminder bool
} {
{
name : "pending -> ok should not trigger an notification" ,
newState : m . AlertStatePending ,
prevState : m . AlertStateOK ,
expected : false ,
} ,
{
name : "ok -> alerting should trigger an notification" ,
newState : m . AlertStateOK ,
prevState : m . AlertStateAlerting ,
expected : true ,
} ,
{
name : "ok -> pending should not trigger an notification" ,
newState : m . AlertStateOK ,
prevState : m . AlertStatePending ,
expected : false ,
} ,
{
name : "ok -> ok should not trigger an notification" ,
newState : m . AlertStateOK ,
prevState : m . AlertStateOK ,
expected : false ,
sendReminder : false ,
} ,
{
name : "ok -> alerting should not trigger an notification" ,
newState : m . AlertStateOK ,
prevState : m . AlertStateAlerting ,
expected : true ,
sendReminder : true ,
} ,
{
name : "ok -> ok with reminder should not trigger an notification" ,
newState : m . AlertStateOK ,
prevState : m . AlertStateOK ,
expected : false ,
sendReminder : true ,
} ,
}
for _ , tc := range tcs {
context := alerting . NewEvalContext ( context . TODO ( ) , & alerting . Rule {
evalC ontext := alerting . NewEvalContext ( context . TODO ( ) , & alerting . Rule {
State : tc . newState ,
} )
context . Rule . State = tc . prevState
evalC ontext. Rule . State = tc . prevState
timeNow := time . Now ( )
if defaultShouldNotify ( context , true , 0 , & timeNow ) != tc . expected {
t . Errorf ( "expected %v to return %v" , tc , tc . expected )
if defaultShouldNotify ( evalC ontext, true , 0 , & timeNow ) != tc . expected {
t . Errorf ( "failed %s. expected %+ v to return %v" , tc . name , tc , tc . expected )
}
}
}