eval_handler_test.go 885 B

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