stackdriver_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 TestStackdriver(t *testing.T) {
  11. Convey("Stackdriver", t, func() {
  12. Convey("Parse query from frontend", func() {
  13. executor := &StackdriverExecutor{}
  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. "target": "target",
  24. "metricType": "time_series",
  25. }),
  26. RefId: "A",
  27. },
  28. },
  29. }
  30. queries, err := executor.parseQueries(tsdbQuery)
  31. So(err, ShouldBeNil)
  32. So(len(queries), ShouldEqual, 1)
  33. So(queries[0].RefID, ShouldEqual, "A")
  34. So(queries[0].Target, ShouldEqual, "target")
  35. So(len(queries[0].Params), ShouldEqual, 4)
  36. So(queries[0].Params["interval.startTime"][0], ShouldEqual, "2018-03-15T13:00:00Z")
  37. So(queries[0].Params["interval.endTime"][0], ShouldEqual, "2018-03-15T13:34:00Z")
  38. So(queries[0].Params["aggregation.perSeriesAligner"][0], ShouldEqual, "ALIGN_NONE")
  39. So(queries[0].Params["filter"][0], ShouldEqual, "time_series")
  40. })
  41. })
  42. }