grafana/pkg/services/alerting/eval_handler_test.go

47 lines
1.0 KiB
Go
Raw Normal View History

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