query_part_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package influxdb
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func TestInfluxdbQueryPart(t *testing.T) {
  7. Convey("Influxdb query part builder", t, func() {
  8. Convey("should handle field renderer parts", func() {
  9. part := QueryPart{
  10. Type: "field",
  11. Params: []string{"value"},
  12. }
  13. res, _ := part.Render("value")
  14. So(res, ShouldEqual, `"value"`)
  15. })
  16. Convey("should handle nested function parts", func() {
  17. part := QueryPart{
  18. Type: "derivative",
  19. Params: []string{"10s"},
  20. }
  21. res, _ := part.Render("mean(value)")
  22. So(res, ShouldEqual, "derivative(mean(value), 10s)")
  23. })
  24. Convey("should nest spread function", func() {
  25. part := QueryPart{
  26. Type: "spread",
  27. }
  28. res, err := part.Render("value")
  29. So(err, ShouldBeNil)
  30. So(res, ShouldEqual, "spread(value)")
  31. })
  32. Convey("should handle suffix parts", func() {
  33. part := QueryPart{
  34. Type: "math",
  35. Params: []string{"/ 100"},
  36. }
  37. res, _ := part.Render("mean(value)")
  38. So(res, ShouldEqual, "mean(value) / 100")
  39. })
  40. Convey("should handle alias parts", func() {
  41. part := QueryPart{
  42. Type: "alias",
  43. Params: []string{"test"},
  44. }
  45. res, _ := part.Render("mean(value)")
  46. So(res, ShouldEqual, `mean(value) AS "test"`)
  47. })
  48. })
  49. }