2016-07-27 09:29:28 -05:00
|
|
|
package alerting
|
|
|
|
|
|
|
|
import (
|
2016-10-03 02:38:03 -05:00
|
|
|
"context"
|
2016-07-27 09:29:28 -05:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
|
|
|
type conditionStub struct {
|
|
|
|
firing bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *conditionStub) Eval(context *EvalContext) {
|
|
|
|
context.Firing = c.firing
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlertingExecutor(t *testing.T) {
|
|
|
|
Convey("Test alert execution", t, func() {
|
|
|
|
handler := NewEvalHandler()
|
|
|
|
|
|
|
|
Convey("Show return triggered with single passing condition", func() {
|
2016-10-03 02:38:03 -05:00
|
|
|
context := NewEvalContext(context.TODO(), &Rule{
|
2016-07-27 09:29:28 -05:00
|
|
|
Conditions: []Condition{&conditionStub{
|
|
|
|
firing: true,
|
|
|
|
}},
|
|
|
|
})
|
|
|
|
|
2016-10-03 02:38:03 -05:00
|
|
|
handler.Eval(context)
|
2016-07-27 09:29:28 -05:00
|
|
|
So(context.Firing, ShouldEqual, true)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Show return false with not passing condition", func() {
|
2016-10-03 02:38:03 -05:00
|
|
|
context := NewEvalContext(context.TODO(), &Rule{
|
2016-07-27 09:29:28 -05:00
|
|
|
Conditions: []Condition{
|
|
|
|
&conditionStub{firing: true},
|
|
|
|
&conditionStub{firing: false},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2016-10-03 02:38:03 -05:00
|
|
|
handler.Eval(context)
|
2016-07-27 09:29:28 -05:00
|
|
|
So(context.Firing, ShouldEqual, false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|