eval_handler_test.go 928 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package alerting
  2. import (
  3. "context"
  4. "testing"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. type conditionStub struct {
  8. firing bool
  9. }
  10. func (c *conditionStub) Eval(context *EvalContext) {
  11. context.Firing = c.firing
  12. }
  13. func TestAlertingExecutor(t *testing.T) {
  14. Convey("Test alert execution", t, func() {
  15. handler := NewEvalHandler()
  16. Convey("Show return triggered with single passing condition", func() {
  17. context := NewEvalContext(context.TODO(), &Rule{
  18. Conditions: []Condition{&conditionStub{
  19. firing: true,
  20. }},
  21. })
  22. handler.Eval(context)
  23. So(context.Firing, ShouldEqual, true)
  24. })
  25. Convey("Show return false with not passing condition", func() {
  26. context := NewEvalContext(context.TODO(), &Rule{
  27. Conditions: []Condition{
  28. &conditionStub{firing: true},
  29. &conditionStub{firing: false},
  30. },
  31. })
  32. handler.Eval(context)
  33. So(context.Firing, ShouldEqual, false)
  34. })
  35. })
  36. }