prometheus_test.go 949 B

123456789101112131415161718192021222324252627282930313233343536373839
  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("app"): p.LabelValue("backend"),
  22. p.LabelName("device"): p.LabelValue("mobile"),
  23. }
  24. query := &PrometheusQuery{
  25. LegendFormat: "",
  26. }
  27. So(formatLegend(metric, query), ShouldEqual, `http_request_total{app="backend", device="mobile"}`)
  28. })
  29. })
  30. }