2016-10-06 20:16:26 +08:00
|
|
|
package influxdb
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestInfluxdbResponseParser(t *testing.T) {
|
|
|
|
|
Convey("Influxdb response parser", t, func() {
|
|
|
|
|
|
2016-10-06 21:30:09 +08:00
|
|
|
parser := &ResponseParser{}
|
2016-10-06 20:16:26 +08:00
|
|
|
|
|
|
|
|
response := &Response{
|
|
|
|
|
Results: []Result{
|
|
|
|
|
Result{
|
|
|
|
|
Series: []Row{
|
|
|
|
|
{
|
|
|
|
|
Name: "cpu",
|
|
|
|
|
Columns: []string{"time", "mean", "sum"},
|
2016-10-06 21:30:09 +08:00
|
|
|
Tags: map[string]string{"datacenter": "America"},
|
2016-10-06 20:16:26 +08:00
|
|
|
Values: [][]interface{}{
|
2016-10-06 21:30:09 +08:00
|
|
|
{json.Number("111"), json.Number("222"), json.Number("333")},
|
|
|
|
|
{json.Number("111"), json.Number("222"), json.Number("333")},
|
|
|
|
|
{json.Number("111"), json.Number("null"), json.Number("333")},
|
2016-10-06 20:16:26 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-06 21:30:09 +08:00
|
|
|
result := parser.Parse(response)
|
|
|
|
|
|
|
|
|
|
Convey("can parse all series", func() {
|
|
|
|
|
So(len(result.Series), ShouldEqual, 2)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Convey("can parse all points", func() {
|
|
|
|
|
So(len(result.Series[0].Points), ShouldEqual, 3)
|
|
|
|
|
So(len(result.Series[1].Points), ShouldEqual, 3)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Convey("can parse multi row result", func() {
|
|
|
|
|
So(result.Series[0].Points[1][0].Float64, ShouldEqual, float64(222))
|
|
|
|
|
So(result.Series[1].Points[1][0].Float64, ShouldEqual, float64(333))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Convey("can parse null points", func() {
|
|
|
|
|
So(result.Series[0].Points[2][0].Valid, ShouldBeFalse)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Convey("can format serie names", func() {
|
2016-10-07 00:47:59 +08:00
|
|
|
So(result.Series[0].Name, ShouldEqual, "cpu.mean { datacenter: America }")
|
|
|
|
|
So(result.Series[1].Name, ShouldEqual, "cpu.sum { datacenter: America }")
|
2016-10-06 20:16:26 +08:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|