victorops_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package notifiers
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. "github.com/grafana/grafana/pkg/models"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestVictoropsNotifier(t *testing.T) {
  9. Convey("Victorops 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 := &models.AlertNotification{
  15. Name: "victorops_testing",
  16. Type: "victorops",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewVictoropsNotifier(model)
  20. So(err, ShouldNotBeNil)
  21. })
  22. Convey("from settings", func() {
  23. json := `
  24. {
  25. "url": "http://google.com"
  26. }`
  27. settingsJSON, _ := simplejson.NewJson([]byte(json))
  28. model := &models.AlertNotification{
  29. Name: "victorops_testing",
  30. Type: "victorops",
  31. Settings: settingsJSON,
  32. }
  33. not, err := NewVictoropsNotifier(model)
  34. victoropsNotifier := not.(*VictoropsNotifier)
  35. So(err, ShouldBeNil)
  36. So(victoropsNotifier.Name, ShouldEqual, "victorops_testing")
  37. So(victoropsNotifier.Type, ShouldEqual, "victorops")
  38. So(victoropsNotifier.URL, ShouldEqual, "http://google.com")
  39. })
  40. })
  41. })
  42. }