|
|
@@ -11,27 +11,86 @@ import (
|
|
|
|
|
|
func TestTestdataScenarios(t *testing.T) {
|
|
|
Convey("random walk ", t, func() {
|
|
|
- if scenario, exist := ScenarioRegistry["random_walk"]; exist {
|
|
|
-
|
|
|
- Convey("Should start at the requested value", func() {
|
|
|
- req := &tsdb.TsdbQuery{
|
|
|
- TimeRange: tsdb.NewFakeTimeRange("5m", "now", time.Now()),
|
|
|
- Queries: []*tsdb.Query{
|
|
|
- {RefId: "A", IntervalMs: 100, MaxDataPoints: 10, Model: simplejson.New()},
|
|
|
- },
|
|
|
- }
|
|
|
- query := req.Queries[0]
|
|
|
- query.Model.Set("startValue", 1.234)
|
|
|
+ scenario, exist := ScenarioRegistry["random_walk"]
|
|
|
+ So(exist, ShouldBeTrue)
|
|
|
+
|
|
|
+ Convey("Should start at the requested value", func() {
|
|
|
+ req := &tsdb.TsdbQuery{
|
|
|
+ TimeRange: tsdb.NewFakeTimeRange("5m", "now", time.Now()),
|
|
|
+ Queries: []*tsdb.Query{
|
|
|
+ {RefId: "A", IntervalMs: 100, MaxDataPoints: 100, Model: simplejson.New()},
|
|
|
+ },
|
|
|
+ }
|
|
|
+ query := req.Queries[0]
|
|
|
+ query.Model.Set("startValue", 1.234)
|
|
|
+
|
|
|
+ result := scenario.Handler(req.Queries[0], req)
|
|
|
+ points := result.Series[0].Points
|
|
|
+
|
|
|
+ So(result.Series, ShouldNotBeNil)
|
|
|
+ So(points[0][0].Float64, ShouldEqual, 1.234)
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ Convey("random walk table", t, func() {
|
|
|
+ scenario, exist := ScenarioRegistry["random_walk_table"]
|
|
|
+ So(exist, ShouldBeTrue)
|
|
|
+
|
|
|
+ Convey("Should return a table that looks like value/min/max", func() {
|
|
|
+ req := &tsdb.TsdbQuery{
|
|
|
+ TimeRange: tsdb.NewFakeTimeRange("5m", "now", time.Now()),
|
|
|
+ Queries: []*tsdb.Query{
|
|
|
+ {RefId: "A", IntervalMs: 100, MaxDataPoints: 100, Model: simplejson.New()},
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ result := scenario.Handler(req.Queries[0], req)
|
|
|
+ table := result.Tables[0]
|
|
|
|
|
|
- result := scenario.Handler(req.Queries[0], req)
|
|
|
- points := result.Series[0].Points
|
|
|
+ So(len(table.Rows), ShouldBeGreaterThan, 50)
|
|
|
+ for _, row := range table.Rows {
|
|
|
+ value := row[1]
|
|
|
+ min := row[2]
|
|
|
+ max := row[3]
|
|
|
|
|
|
- So(result.Series, ShouldNotBeNil)
|
|
|
- So(points[0][0].Float64, ShouldEqual, 1.234)
|
|
|
- })
|
|
|
+ So(min, ShouldBeLessThan, value)
|
|
|
+ So(max, ShouldBeGreaterThan, value)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ Convey("Should return a table with some nil values", func() {
|
|
|
+ req := &tsdb.TsdbQuery{
|
|
|
+ TimeRange: tsdb.NewFakeTimeRange("5m", "now", time.Now()),
|
|
|
+ Queries: []*tsdb.Query{
|
|
|
+ {RefId: "A", IntervalMs: 100, MaxDataPoints: 100, Model: simplejson.New()},
|
|
|
+ },
|
|
|
+ }
|
|
|
+ query := req.Queries[0]
|
|
|
+ query.Model.Set("withNil", true)
|
|
|
+
|
|
|
+ result := scenario.Handler(req.Queries[0], req)
|
|
|
+ table := result.Tables[0]
|
|
|
+
|
|
|
+ nil1 := false
|
|
|
+ nil2 := false
|
|
|
+ nil3 := false
|
|
|
+
|
|
|
+ So(len(table.Rows), ShouldBeGreaterThan, 50)
|
|
|
+ for _, row := range table.Rows {
|
|
|
+ if row[1] == nil {
|
|
|
+ nil1 = true
|
|
|
+ }
|
|
|
+ if row[2] == nil {
|
|
|
+ nil2 = true
|
|
|
+ }
|
|
|
+ if row[3] == nil {
|
|
|
+ nil3 = true
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
- t.Fail()
|
|
|
- }
|
|
|
+ So(nil1, ShouldBeTrue)
|
|
|
+ So(nil2, ShouldBeTrue)
|
|
|
+ So(nil3, ShouldBeTrue)
|
|
|
+ })
|
|
|
})
|
|
|
}
|