line_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 TestLineNotifier(t *testing.T) {
  9. Convey("Line notifier tests", t, func() {
  10. Convey("empty settings should return error", func() {
  11. json := `{ }`
  12. settingsJSON, _ := simplejson.NewJson([]byte(json))
  13. model := &m.AlertNotification{
  14. Name: "line_testing",
  15. Type: "line",
  16. Settings: settingsJSON,
  17. }
  18. _, err := NewLINENotifier(model)
  19. So(err, ShouldNotBeNil)
  20. })
  21. Convey("settings should trigger incident", func() {
  22. json := `
  23. {
  24. "token": "abcdefgh0123456789"
  25. }`
  26. settingsJSON, _ := simplejson.NewJson([]byte(json))
  27. model := &m.AlertNotification{
  28. Name: "line_testing",
  29. Type: "line",
  30. Settings: settingsJSON,
  31. }
  32. not, err := NewLINENotifier(model)
  33. lineNotifier := not.(*LineNotifier)
  34. So(err, ShouldBeNil)
  35. So(lineNotifier.Name, ShouldEqual, "line_testing")
  36. So(lineNotifier.Type, ShouldEqual, "line")
  37. So(lineNotifier.Token, ShouldEqual, "abcdefgh0123456789")
  38. })
  39. })
  40. }