grafana/pkg/tsdb/influxdb/parser_test.go

108 lines
2.6 KiB
Go
Raw Normal View History

2016-10-05 03:56:34 -05:00
package influxdb
import (
"testing"
"github.com/grafana/grafana/pkg/components/simplejson"
. "github.com/smartystreets/goconvey/convey"
)
func TestInfluxdbQueryParser(t *testing.T) {
Convey("Influxdb query parser", t, func() {
parser := &InfluxdbQueryParser{}
Convey("converting metric name", func() {
json := `
{
"dsType": "influxdb",
"groupBy": [
{
"params": [
"$interval"
],
"type": "time"
},
{
"params": [
"datacenter"
],
"type": "tag"
},
{
"params": [
"null"
],
"type": "fill"
}
2016-10-05 03:56:34 -05:00
],
"measurement": "logins.count",
"policy": "default",
"refId": "B",
"resultFormat": "time_series",
"select": [
[
{
"type": "field",
"params": [
"value"
]
},
{
"type": "count",
"params": []
}
],
[
{
"type": "field",
"params": [
"value"
]
},
{
"type": "mean",
"params": []
}
],
[
{
"type": "field",
"params": [
"value"
]
},
{
"type": "mean",
"params": []
},
{
"type": "math",
"params": [
" / 100"
]
}
]
2016-10-05 03:56:34 -05:00
],
"tags": [
{
"key": "datacenter",
"operator": "=",
"value": "America"
}
]
2016-10-05 03:56:34 -05:00
}
`
modelJson, err := simplejson.NewJson([]byte(json))
So(err, ShouldBeNil)
res, err := parser.Parse(modelJson)
So(err, ShouldBeNil)
So(len(res.GroupBy), ShouldEqual, 3)
So(len(res.Selects), ShouldEqual, 3)
2016-10-05 03:56:34 -05:00
So(len(res.Tags), ShouldEqual, 1)
})
})
}