sensu_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. "source": "grafana_instance_01",
  27. "handler": "myhandler"
  28. }`
  29. settingsJSON, _ := simplejson.NewJson([]byte(json))
  30. model := &m.AlertNotification{
  31. Name: "sensu",
  32. Type: "sensu",
  33. Settings: settingsJSON,
  34. }
  35. not, err := NewSensuNotifier(model)
  36. sensuNotifier := not.(*SensuNotifier)
  37. So(err, ShouldBeNil)
  38. So(sensuNotifier.Name, ShouldEqual, "sensu")
  39. So(sensuNotifier.Type, ShouldEqual, "sensu")
  40. So(sensuNotifier.Url, ShouldEqual, "http://sensu-api.example.com:4567/results")
  41. So(sensuNotifier.Source, ShouldEqual, "grafana_instance_01")
  42. So(sensuNotifier.Handler, ShouldEqual, "myhandler")
  43. })
  44. })
  45. })
  46. }