|
|
@@ -3,6 +3,8 @@ package conditions
|
|
|
import (
|
|
|
"testing"
|
|
|
|
|
|
+ null "gopkg.in/guregu/null.v3"
|
|
|
+
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
|
@@ -41,9 +43,8 @@ func TestQueryCondition(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
Convey("should fire when avg is above 100", func() {
|
|
|
- one := float64(120)
|
|
|
- two := float64(0)
|
|
|
- ctx.series = tsdb.TimeSeriesSlice{tsdb.NewTimeSeries("test1", [][2]*float64{{&one, &two}})}
|
|
|
+ points := tsdb.NewTimeSeriesPointsFromArgs(120, 0)
|
|
|
+ ctx.series = tsdb.TimeSeriesSlice{tsdb.NewTimeSeries("test1", points)}
|
|
|
ctx.exec()
|
|
|
|
|
|
So(ctx.result.Error, ShouldBeNil)
|
|
|
@@ -51,9 +52,8 @@ func TestQueryCondition(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
Convey("Should not fire when avg is below 100", func() {
|
|
|
- one := float64(90)
|
|
|
- two := float64(0)
|
|
|
- ctx.series = tsdb.TimeSeriesSlice{tsdb.NewTimeSeries("test1", [][2]*float64{{&one, &two}})}
|
|
|
+ points := tsdb.NewTimeSeriesPointsFromArgs(90, 0)
|
|
|
+ ctx.series = tsdb.TimeSeriesSlice{tsdb.NewTimeSeries("test1", points)}
|
|
|
ctx.exec()
|
|
|
|
|
|
So(ctx.result.Error, ShouldBeNil)
|
|
|
@@ -61,11 +61,9 @@ func TestQueryCondition(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
Convey("Should fire if only first serie matches", func() {
|
|
|
- one := float64(120)
|
|
|
- two := float64(0)
|
|
|
ctx.series = tsdb.TimeSeriesSlice{
|
|
|
- tsdb.NewTimeSeries("test1", [][2]*float64{{&one, &two}}),
|
|
|
- tsdb.NewTimeSeries("test2", [][2]*float64{{&two, &two}}),
|
|
|
+ tsdb.NewTimeSeries("test1", tsdb.NewTimeSeriesPointsFromArgs(120, 0)),
|
|
|
+ tsdb.NewTimeSeries("test2", tsdb.NewTimeSeriesPointsFromArgs(0, 0)),
|
|
|
}
|
|
|
ctx.exec()
|
|
|
|
|
|
@@ -76,8 +74,8 @@ func TestQueryCondition(t *testing.T) {
|
|
|
Convey("Empty series", func() {
|
|
|
Convey("Should set NoDataFound both series are empty", func() {
|
|
|
ctx.series = tsdb.TimeSeriesSlice{
|
|
|
- tsdb.NewTimeSeries("test1", [][2]*float64{}),
|
|
|
- tsdb.NewTimeSeries("test2", [][2]*float64{}),
|
|
|
+ tsdb.NewTimeSeries("test1", tsdb.NewTimeSeriesPointsFromArgs()),
|
|
|
+ tsdb.NewTimeSeries("test2", tsdb.NewTimeSeriesPointsFromArgs()),
|
|
|
}
|
|
|
ctx.exec()
|
|
|
|
|
|
@@ -86,10 +84,9 @@ func TestQueryCondition(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
Convey("Should set NoDataFound both series contains null", func() {
|
|
|
- one := float64(120)
|
|
|
ctx.series = tsdb.TimeSeriesSlice{
|
|
|
- tsdb.NewTimeSeries("test1", [][2]*float64{{nil, &one}}),
|
|
|
- tsdb.NewTimeSeries("test2", [][2]*float64{{nil, &one}}),
|
|
|
+ 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()
|
|
|
|
|
|
@@ -98,11 +95,9 @@ func TestQueryCondition(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
Convey("Should not set NoDataFound if one serie is empty", func() {
|
|
|
- one := float64(120)
|
|
|
- two := float64(0)
|
|
|
ctx.series = tsdb.TimeSeriesSlice{
|
|
|
- tsdb.NewTimeSeries("test1", [][2]*float64{}),
|
|
|
- tsdb.NewTimeSeries("test2", [][2]*float64{{&one, &two}}),
|
|
|
+ tsdb.NewTimeSeries("test1", tsdb.NewTimeSeriesPointsFromArgs()),
|
|
|
+ tsdb.NewTimeSeries("test2", tsdb.NewTimeSeriesPointsFromArgs(120, 0)),
|
|
|
}
|
|
|
ctx.exec()
|
|
|
|