parser_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package influxdb
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestInfluxdbQueryParser(t *testing.T) {
  8. Convey("Influxdb query parser", t, func() {
  9. parser := &InfluxdbQueryParser{}
  10. Convey("converting metric name", func() {
  11. json := `
  12. {
  13. "dsType": "influxdb",
  14. "groupBy": [
  15. {
  16. "params": [
  17. "$interval"
  18. ],
  19. "type": "time"
  20. },
  21. {
  22. "type": "tag",
  23. "params": [
  24. "datacenter"
  25. ]
  26. },
  27. {
  28. "params": [
  29. "null"
  30. ],
  31. "type": "fill"
  32. }
  33. ],
  34. "measurement": "logins.count",
  35. "policy": "default",
  36. "refId": "B",
  37. "resultFormat": "time_series",
  38. "select": [
  39. [
  40. {
  41. "params": [
  42. "value"
  43. ],
  44. "type": "field"
  45. },
  46. {
  47. "params": [
  48. ],
  49. "type": "count"
  50. }
  51. ],
  52. [
  53. {
  54. "params": [
  55. "value"
  56. ],
  57. "type": "field"
  58. },
  59. {
  60. "params": [
  61. ],
  62. "type": "mean"
  63. }
  64. ]
  65. ],
  66. "tags": [
  67. {
  68. "key": "datacenter",
  69. "operator": "=",
  70. "value": "America"
  71. }
  72. ]
  73. }
  74. `
  75. modelJson, err := simplejson.NewJson([]byte(json))
  76. So(err, ShouldBeNil)
  77. res, err := parser.Parse(modelJson)
  78. So(err, ShouldBeNil)
  79. So(len(res.GroupBy), ShouldEqual, 3)
  80. So(len(res.Selects), ShouldEqual, 2)
  81. So(len(res.Tags), ShouldEqual, 1)
  82. })
  83. })
  84. }