eval_handler_test.go 1.0 KB

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