2018-09-24 09:02:35 -05:00
|
|
|
package stackdriver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
|
|
"github.com/grafana/grafana/pkg/tsdb"
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStackdriverAnnotationQuery(t *testing.T) {
|
|
|
|
Convey("Stackdriver Annotation Query Executor", t, func() {
|
|
|
|
executor := &StackdriverExecutor{}
|
2018-09-27 08:17:35 -05:00
|
|
|
Convey("When parsing the stackdriver api response", func() {
|
|
|
|
data, err := loadTestFile("./test-data/2-series-response-no-agg.json")
|
2018-09-24 09:02:35 -05:00
|
|
|
So(err, ShouldBeNil)
|
2018-09-27 08:17:35 -05:00
|
|
|
So(len(data.TimeSeries), ShouldEqual, 3)
|
2018-09-24 09:02:35 -05:00
|
|
|
|
2018-09-27 08:17:35 -05:00
|
|
|
res := &tsdb.QueryResult{Meta: simplejson.New(), RefId: "annotationQuery"}
|
2020-03-27 06:01:16 -05:00
|
|
|
query := &stackdriverQuery{}
|
2018-09-28 07:55:39 -05:00
|
|
|
err = executor.parseToAnnotations(res, data, query, "atitle {{metric.label.instance_name}} {{metric.value}}", "atext {{resource.label.zone}}", "atag")
|
2018-09-27 08:17:35 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
Convey("Should return annotations table", func() {
|
|
|
|
So(len(res.Tables), ShouldEqual, 1)
|
|
|
|
So(len(res.Tables[0].Rows), ShouldEqual, 9)
|
2018-09-27 09:16:09 -05:00
|
|
|
So(res.Tables[0].Rows[0][1], ShouldEqual, "atitle collector-asia-east-1 9.856650")
|
|
|
|
So(res.Tables[0].Rows[0][3], ShouldEqual, "atext asia-east1-a")
|
2018-09-27 08:17:35 -05:00
|
|
|
})
|
2018-09-24 09:02:35 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|