alertmanager_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package notifiers
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. m "github.com/grafana/grafana/pkg/models"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestAlertmanagerNotifier(t *testing.T) {
  9. Convey("Alertmanager notifier tests", t, func() {
  10. Convey("Parsing alert notification from settings", func() {
  11. Convey("empty settings should return error", func() {
  12. json := `{ }`
  13. settingsJSON, _ := simplejson.NewJson([]byte(json))
  14. model := &m.AlertNotification{
  15. Name: "alertmanager",
  16. Type: "alertmanager",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewAlertmanagerNotifier(model)
  20. So(err, ShouldNotBeNil)
  21. })
  22. Convey("from settings", func() {
  23. json := `{ "url": "http://127.0.0.1:9093/" }`
  24. settingsJSON, _ := simplejson.NewJson([]byte(json))
  25. model := &m.AlertNotification{
  26. Name: "alertmanager",
  27. Type: "alertmanager",
  28. Settings: settingsJSON,
  29. }
  30. not, err := NewAlertmanagerNotifier(model)
  31. alertmanagerNotifier := not.(*AlertmanagerNotifier)
  32. So(err, ShouldBeNil)
  33. So(alertmanagerNotifier.Url, ShouldEqual, "http://127.0.0.1:9093/")
  34. })
  35. })
  36. })
  37. }