telegram_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 TestTelegramNotifier(t *testing.T) {
  9. Convey("Telegram 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: "telegram_testing",
  16. Type: "telegram",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewTelegramNotifier(model)
  20. So(err, ShouldNotBeNil)
  21. })
  22. Convey("settings should trigger incident", func() {
  23. json := `
  24. {
  25. "bottoken": "abcdefgh0123456789",
  26. "chatid": "-1234567890"
  27. }`
  28. settingsJSON, _ := simplejson.NewJson([]byte(json))
  29. model := &m.AlertNotification{
  30. Name: "telegram_testing",
  31. Type: "telegram",
  32. Settings: settingsJSON,
  33. }
  34. not, err := NewTelegramNotifier(model)
  35. telegramNotifier := not.(*TelegramNotifier)
  36. So(err, ShouldBeNil)
  37. So(telegramNotifier.Name, ShouldEqual, "telegram_testing")
  38. So(telegramNotifier.Type, ShouldEqual, "telegram")
  39. So(telegramNotifier.BotToken, ShouldEqual, "abcdefgh0123456789")
  40. So(telegramNotifier.ChatID, ShouldEqual, "-1234567890")
  41. })
  42. })
  43. })
  44. }