graphite_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package metrics
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/setting"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestGraphitePublisher(t *testing.T) {
  8. Convey("Test graphite prefix replacement", t, func() {
  9. var err error
  10. err = setting.NewConfigContext(&setting.CommandLineArgs{
  11. HomePath: "../../",
  12. })
  13. So(err, ShouldBeNil)
  14. sec, err := setting.Cfg.NewSection("metrics.graphite")
  15. sec.NewKey("prefix", "service.grafana.%(instance_name)s.")
  16. sec.NewKey("address", "localhost:2001")
  17. So(err, ShouldBeNil)
  18. setting.InstanceName = "hostname.with.dots.com"
  19. publisher, err := CreateGraphitePublisher()
  20. So(err, ShouldBeNil)
  21. So(publisher, ShouldNotBeNil)
  22. So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.")
  23. So(publisher.address, ShouldEqual, "localhost:2001")
  24. })
  25. Convey("Test graphite publisher default values", t, func() {
  26. var err error
  27. err = setting.NewConfigContext(&setting.CommandLineArgs{
  28. HomePath: "../../",
  29. })
  30. So(err, ShouldBeNil)
  31. _, err = setting.Cfg.NewSection("metrics.graphite")
  32. setting.InstanceName = "hostname.with.dots.com"
  33. publisher, err := CreateGraphitePublisher()
  34. So(err, ShouldBeNil)
  35. So(publisher, ShouldNotBeNil)
  36. So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.")
  37. So(publisher.address, ShouldEqual, "localhost:2003")
  38. })
  39. }