annotation_query_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. package stackdriver
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. "github.com/grafana/grafana/pkg/tsdb"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestStackdriverAnnotationQuery(t *testing.T) {
  9. Convey("Stackdriver Annotation Query Executor", t, func() {
  10. executor := &StackdriverExecutor{}
  11. Convey("When parsing the stackdriver api response", func() {
  12. data, err := loadTestFile("./test-data/2-series-response-no-agg.json")
  13. So(err, ShouldBeNil)
  14. So(len(data.TimeSeries), ShouldEqual, 3)
  15. res := &tsdb.QueryResult{Meta: simplejson.New(), RefId: "annotationQuery"}
  16. query := &StackdriverQuery{}
  17. err = executor.parseToAnnotations(res, data, query, "atitle {{metric.label.instance_name}} {{metric.value}}", "atext {{resource.label.zone}}", "atag")
  18. So(err, ShouldBeNil)
  19. Convey("Should return annotations table", func() {
  20. So(len(res.Tables), ShouldEqual, 1)
  21. So(len(res.Tables[0].Rows), ShouldEqual, 9)
  22. So(res.Tables[0].Rows[0][1], ShouldEqual, "atitle collector-asia-east-1 9.856650")
  23. So(res.Tables[0].Rows[0][3], ShouldEqual, "atext asia-east1-a")
  24. })
  25. })
  26. })
  27. }