eval_context_test.go 747 B

1234567891011121314151617181920212223242526272829303132
  1. package alerting
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/grafana/grafana/pkg/models"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestAlertingEvalContext(t *testing.T) {
  9. Convey("Eval context", t, func() {
  10. ctx := NewEvalContext(context.TODO(), &Rule{Conditions: []Condition{&conditionStub{firing: true}}})
  11. Convey("Should update alert state", func() {
  12. Convey("ok -> alerting", func() {
  13. ctx.PrevAlertState = models.AlertStateOK
  14. ctx.Rule.State = models.AlertStateAlerting
  15. So(ctx.ShouldUpdateAlertState(), ShouldBeTrue)
  16. })
  17. Convey("ok -> ok", func() {
  18. ctx.PrevAlertState = models.AlertStateOK
  19. ctx.Rule.State = models.AlertStateOK
  20. So(ctx.ShouldUpdateAlertState(), ShouldBeFalse)
  21. })
  22. })
  23. })
  24. }