prometheus_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package prometheus
  2. import (
  3. "testing"
  4. p "github.com/prometheus/common/model"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestPrometheus(t *testing.T) {
  8. Convey("Prometheus", t, func() {
  9. Convey("converting metric name", func() {
  10. metric := map[p.LabelName]p.LabelValue{
  11. p.LabelName("app"): p.LabelValue("backend"),
  12. p.LabelName("device"): p.LabelValue("mobile"),
  13. }
  14. query := &PrometheusQuery{
  15. LegendFormat: "legend {{app}} {{ device }} {{broken}}",
  16. }
  17. So(formatLegend(metric, query), ShouldEqual, "legend backend mobile {{broken}}")
  18. })
  19. Convey("build full serie name", func() {
  20. metric := map[p.LabelName]p.LabelValue{
  21. p.LabelName(p.MetricNameLabel): p.LabelValue("http_request_total"),
  22. p.LabelName("app"): p.LabelValue("backend"),
  23. p.LabelName("device"): p.LabelValue("mobile"),
  24. }
  25. query := &PrometheusQuery{
  26. LegendFormat: "",
  27. }
  28. So(formatLegend(metric, query), ShouldEqual, `http_request_total{app="backend", device="mobile"}`)
  29. })
  30. })
  31. }