sensu_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 TestSensuNotifier(t *testing.T) {
  9. Convey("Sensu 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: "sensu",
  16. Type: "sensu",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewSensuNotifier(model)
  20. So(err, ShouldNotBeNil)
  21. })
  22. Convey("from settings", func() {
  23. json := `
  24. {
  25. "url": "http://sensu-api.example.com:4567/results"
  26. }`
  27. settingsJSON, _ := simplejson.NewJson([]byte(json))
  28. model := &m.AlertNotification{
  29. Name: "sensu",
  30. Type: "sensu",
  31. Settings: settingsJSON,
  32. }
  33. not, err := NewSensuNotifier(model)
  34. sensuNotifier := not.(*SensuNotifier)
  35. So(err, ShouldBeNil)
  36. So(sensuNotifier.Name, ShouldEqual, "sensu")
  37. So(sensuNotifier.Type, ShouldEqual, "sensu")
  38. So(sensuNotifier.Url, ShouldEqual, "http://sensu-api.example.com:4567/results")
  39. })
  40. })
  41. })
  42. }