mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
489f087fbd
ref #6444
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package alerting
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
func TestAlertingEvalContext(t *testing.T) {
|
|
Convey("Eval context", t, func() {
|
|
ctx := NewEvalContext(context.TODO(), &Rule{Conditions: []Condition{&conditionStub{firing: true}}})
|
|
|
|
Convey("Should update alert state", func() {
|
|
|
|
Convey("ok -> alerting", func() {
|
|
ctx.PrevAlertState = models.AlertStateOK
|
|
ctx.Rule.State = models.AlertStateAlerting
|
|
|
|
So(ctx.ShouldUpdateAlertState(), ShouldBeTrue)
|
|
})
|
|
|
|
Convey("ok -> ok", func() {
|
|
ctx.PrevAlertState = models.AlertStateOK
|
|
ctx.Rule.State = models.AlertStateOK
|
|
|
|
So(ctx.ShouldUpdateAlertState(), ShouldBeFalse)
|
|
})
|
|
})
|
|
|
|
Convey("Should send notifications", func() {
|
|
Convey("pending -> ok", func() {
|
|
ctx.PrevAlertState = models.AlertStatePending
|
|
ctx.Rule.State = models.AlertStateOK
|
|
|
|
So(ctx.ShouldSendNotification(), ShouldBeFalse)
|
|
})
|
|
|
|
Convey("ok -> alerting", func() {
|
|
ctx.PrevAlertState = models.AlertStateOK
|
|
ctx.Rule.State = models.AlertStateAlerting
|
|
|
|
So(ctx.ShouldSendNotification(), ShouldBeTrue)
|
|
})
|
|
})
|
|
})
|
|
}
|