response_parser_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package mqe
  2. import (
  3. "testing"
  4. "net/http"
  5. "strings"
  6. "io/ioutil"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. var (
  10. dummieJson string
  11. )
  12. func TestMQEResponseParser(t *testing.T) {
  13. Convey("MQE response parser", t, func() {
  14. parser := NewResponseParser()
  15. Convey("Can parse response", func() {
  16. response := &http.Response{
  17. StatusCode: 200,
  18. Body: ioutil.NopCloser(strings.NewReader(dummieJson)),
  19. }
  20. res, err := parser.Parse(response)
  21. So(err, ShouldBeNil)
  22. So(len(res.Series), ShouldEqual, 2)
  23. So(len(res.Series[0].Points), ShouldEqual, 11)
  24. })
  25. })
  26. }
  27. func init() {
  28. dummieJson = `{
  29. "success": true,
  30. "name": "select",
  31. "body": [
  32. {
  33. "query": "os.disk.sda3.weighted_io_time",
  34. "name": "os.disk.sda3.weighted_io_time",
  35. "type": "series",
  36. "series": [
  37. {
  38. "tagset": {
  39. "app": "demoapp",
  40. "host": "staples-lab-1"
  41. },
  42. "values": [1,2,3,4,5,6,7,8,9,10,11]
  43. },
  44. {
  45. "tagset": {
  46. "app": "demoapp",
  47. "host": "staples-lab-2"
  48. },
  49. "values": [11,10,9,8,7,6,5,4,3,2,1]
  50. }
  51. ],
  52. "timerange": {
  53. "start": 1479287280000,
  54. "end": 1479287580000,
  55. "resolution": 30000
  56. }
  57. }
  58. ],
  59. "metadata": {
  60. "description": {
  61. "app": [
  62. "demoapp"
  63. ],
  64. "host": [
  65. "staples-lab-1",
  66. "staples-lab-2"
  67. ]
  68. },
  69. "notes": null,
  70. "profile": [
  71. {
  72. "name": "Parsing Query",
  73. "start": "2016-11-16T04:16:21.874354721-05:00",
  74. "finish": "2016-11-16T04:16:21.874762291-05:00"
  75. },
  76. {
  77. "name": "Cassandra GetAllTags",
  78. "start": "2016-11-16T04:16:21.874907171-05:00",
  79. "finish": "2016-11-16T04:16:21.876401922-05:00"
  80. },
  81. {
  82. "name": "CachedMetricMetadataAPI_GetAllTags_Expired",
  83. "start": "2016-11-16T04:16:21.874904751-05:00",
  84. "finish": "2016-11-16T04:16:21.876407852-05:00"
  85. },
  86. {
  87. "name": "CachedMetricMetadataAPI_GetAllTags",
  88. "start": "2016-11-16T04:16:21.874899491-05:00",
  89. "finish": "2016-11-16T04:16:21.876410382-05:00"
  90. },
  91. {
  92. "name": "Blueflood FetchSingleTimeseries Resolution",
  93. "description": "os.disk.sda3.weighted_io_time [app=demoapp,host=staples-lab-1]\n at 30s",
  94. "start": "2016-11-16T04:16:21.876623312-05:00",
  95. "finish": "2016-11-16T04:16:21.881763444-05:00"
  96. },
  97. {
  98. "name": "Blueflood FetchSingleTimeseries Resolution",
  99. "description": "os.disk.sda3.weighted_io_time [app=demoapp,host=staples-lab-2]\n at 30s",
  100. "start": "2016-11-16T04:16:21.876642682-05:00",
  101. "finish": "2016-11-16T04:16:21.881895914-05:00"
  102. },
  103. {
  104. "name": "Blueflood FetchMultipleTimeseries",
  105. "start": "2016-11-16T04:16:21.876418022-05:00",
  106. "finish": "2016-11-16T04:16:21.881921474-05:00"
  107. }
  108. ]
  109. }
  110. }
  111. `
  112. }