annotation_query_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package stackdriver
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. "github.com/grafana/grafana/pkg/components/simplejson"
  7. "github.com/grafana/grafana/pkg/tsdb"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestStackdriverAnnotationQuery(t *testing.T) {
  11. Convey("Stackdriver Annotation Query Executor", t, func() {
  12. executor := &StackdriverExecutor{}
  13. Convey("Parse queries from frontend and build Stackdriver API queries", func() {
  14. fromStart := time.Date(2018, 3, 15, 13, 0, 0, 0, time.UTC).In(time.Local)
  15. tsdbQuery := &tsdb.TsdbQuery{
  16. TimeRange: &tsdb.TimeRange{
  17. From: fmt.Sprintf("%v", fromStart.Unix()*1000),
  18. To: fmt.Sprintf("%v", fromStart.Add(34*time.Minute).Unix()*1000),
  19. },
  20. Queries: []*tsdb.Query{
  21. {
  22. Model: simplejson.NewFromAny(map[string]interface{}{
  23. "metricType": "a/metric/type",
  24. "view": "FULL",
  25. "type": "annotationQuery",
  26. }),
  27. RefId: "annotationQuery",
  28. },
  29. },
  30. }
  31. query, err := executor.buildAnnotationQuery(tsdbQuery)
  32. So(err, ShouldBeNil)
  33. So(query, ShouldNotBeNil)
  34. })
  35. })
  36. }