fix(alerting): fixes broken no_value evaluator

closes #6701
This commit is contained in:
bergquist 2016-11-27 16:53:29 +01:00
parent 583de8e0e0
commit bdfb773a98
2 changed files with 16 additions and 11 deletions

View File

@ -17,9 +17,9 @@ type AlertEvaluator interface {
Eval(reducedValue null.Float) bool
}
type NoDataEvaluator struct{}
type NoValueEvaluator struct{}
func (e *NoDataEvaluator) Eval(reducedValue null.Float) bool {
func (e *NoValueEvaluator) Eval(reducedValue null.Float) bool {
return reducedValue.Valid == false
}
@ -118,8 +118,8 @@ func NewAlertEvaluator(model *simplejson.Json) (AlertEvaluator, error) {
return newRangedEvaluator(typ, model)
}
if typ == "no_data" {
return &NoDataEvaluator{}, nil
if typ == "no_value" {
return &NoValueEvaluator{}, nil
}
return nil, alerting.ValidationError{Reason: "Evaluator invalid evaluator type: " + typ}

View File

@ -44,15 +44,20 @@ func TestEvalutors(t *testing.T) {
So(evalutorScenario(`{"type": "outside_range", "params": [100, 1] }`, 50), ShouldBeFalse)
})
Convey("no_data", t, func() {
So(evalutorScenario(`{"type": "no_data", "params": [] }`, 50), ShouldBeFalse)
Convey("no_value", t, func() {
Convey("should be false if serie have values", func() {
So(evalutorScenario(`{"type": "no_value", "params": [] }`, 50), ShouldBeFalse)
})
jsonModel, err := simplejson.NewJson([]byte(`{"type": "no_data", "params": [] }`))
So(err, ShouldBeNil)
Convey("should be true when the serie have no value", func() {
jsonModel, err := simplejson.NewJson([]byte(`{"type": "no_value", "params": [] }`))
So(err, ShouldBeNil)
evaluator, err := NewAlertEvaluator(jsonModel)
So(err, ShouldBeNil)
evaluator, err := NewAlertEvaluator(jsonModel)
So(err, ShouldBeNil)
So(evaluator.Eval(null.FloatFromPtr(nil)), ShouldBeTrue)
So(evaluator.Eval(null.FloatFromPtr(nil)), ShouldBeTrue)
})
})
}