|
|
@@ -46,19 +46,19 @@ func TestQueryCondition(t *testing.T) {
|
|
|
Convey("should fire when avg is above 100", func() {
|
|
|
points := tsdb.NewTimeSeriesPointsFromArgs(120, 0)
|
|
|
ctx.series = tsdb.TimeSeriesSlice{tsdb.NewTimeSeries("test1", points)}
|
|
|
- ctx.exec()
|
|
|
+ cr, err := ctx.exec()
|
|
|
|
|
|
- So(ctx.result.Error, ShouldBeNil)
|
|
|
- So(ctx.result.Firing, ShouldBeTrue)
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+ So(cr.Firing, ShouldBeTrue)
|
|
|
})
|
|
|
|
|
|
Convey("Should not fire when avg is below 100", func() {
|
|
|
points := tsdb.NewTimeSeriesPointsFromArgs(90, 0)
|
|
|
ctx.series = tsdb.TimeSeriesSlice{tsdb.NewTimeSeries("test1", points)}
|
|
|
- ctx.exec()
|
|
|
+ cr, err := ctx.exec()
|
|
|
|
|
|
- So(ctx.result.Error, ShouldBeNil)
|
|
|
- So(ctx.result.Firing, ShouldBeFalse)
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+ So(cr.Firing, ShouldBeFalse)
|
|
|
})
|
|
|
|
|
|
Convey("Should fire if only first serie matches", func() {
|
|
|
@@ -66,10 +66,10 @@ func TestQueryCondition(t *testing.T) {
|
|
|
tsdb.NewTimeSeries("test1", tsdb.NewTimeSeriesPointsFromArgs(120, 0)),
|
|
|
tsdb.NewTimeSeries("test2", tsdb.NewTimeSeriesPointsFromArgs(0, 0)),
|
|
|
}
|
|
|
- ctx.exec()
|
|
|
+ cr, err := ctx.exec()
|
|
|
|
|
|
- So(ctx.result.Error, ShouldBeNil)
|
|
|
- So(ctx.result.Firing, ShouldBeTrue)
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+ So(cr.Firing, ShouldBeTrue)
|
|
|
})
|
|
|
|
|
|
Convey("Empty series", func() {
|
|
|
@@ -78,10 +78,10 @@ func TestQueryCondition(t *testing.T) {
|
|
|
tsdb.NewTimeSeries("test1", tsdb.NewTimeSeriesPointsFromArgs()),
|
|
|
tsdb.NewTimeSeries("test2", tsdb.NewTimeSeriesPointsFromArgs()),
|
|
|
}
|
|
|
- ctx.exec()
|
|
|
+ cr, err := ctx.exec()
|
|
|
|
|
|
- So(ctx.result.Error, ShouldBeNil)
|
|
|
- So(ctx.result.NoDataFound, ShouldBeTrue)
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+ So(cr.NoDataFound, ShouldBeTrue)
|
|
|
})
|
|
|
|
|
|
Convey("Should set NoDataFound both series contains null", func() {
|
|
|
@@ -89,10 +89,10 @@ func TestQueryCondition(t *testing.T) {
|
|
|
tsdb.NewTimeSeries("test1", tsdb.TimeSeriesPoints{tsdb.TimePoint{null.FloatFromPtr(nil), null.FloatFrom(0)}}),
|
|
|
tsdb.NewTimeSeries("test2", tsdb.TimeSeriesPoints{tsdb.TimePoint{null.FloatFromPtr(nil), null.FloatFrom(0)}}),
|
|
|
}
|
|
|
- ctx.exec()
|
|
|
+ cr, err := ctx.exec()
|
|
|
|
|
|
- So(ctx.result.Error, ShouldBeNil)
|
|
|
- So(ctx.result.NoDataFound, ShouldBeTrue)
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+ So(cr.NoDataFound, ShouldBeTrue)
|
|
|
})
|
|
|
|
|
|
Convey("Should not set NoDataFound if one serie is empty", func() {
|
|
|
@@ -100,10 +100,10 @@ func TestQueryCondition(t *testing.T) {
|
|
|
tsdb.NewTimeSeries("test1", tsdb.NewTimeSeriesPointsFromArgs()),
|
|
|
tsdb.NewTimeSeries("test2", tsdb.NewTimeSeriesPointsFromArgs(120, 0)),
|
|
|
}
|
|
|
- ctx.exec()
|
|
|
+ cr, err := ctx.exec()
|
|
|
|
|
|
- So(ctx.result.Error, ShouldBeNil)
|
|
|
- So(ctx.result.NoDataFound, ShouldBeFalse)
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+ So(cr.NoDataFound, ShouldBeFalse)
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
@@ -120,7 +120,7 @@ type queryConditionTestContext struct {
|
|
|
|
|
|
type queryConditionScenarioFunc func(c *queryConditionTestContext)
|
|
|
|
|
|
-func (ctx *queryConditionTestContext) exec() {
|
|
|
+func (ctx *queryConditionTestContext) exec() (*alerting.ConditionResult, error) {
|
|
|
jsonModel, err := simplejson.NewJson([]byte(`{
|
|
|
"type": "query",
|
|
|
"query": {
|
|
|
@@ -146,7 +146,7 @@ func (ctx *queryConditionTestContext) exec() {
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
- condition.Eval(ctx.result)
|
|
|
+ return condition.Eval(ctx.result)
|
|
|
}
|
|
|
|
|
|
func queryConditionScenario(desc string, fn queryConditionScenarioFunc) {
|