discord_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 TestDiscordNotifier(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 := &models.AlertNotification{
  15. Name: "discord_testing",
  16. Type: "discord",
  17. Settings: settingsJSON,
  18. }
  19. _, err := newDiscordNotifier(model)
  20. So(err, ShouldNotBeNil)
  21. })
  22. Convey("settings should trigger incident", func() {
  23. json := `
  24. {
  25. "content": "@everyone Please check this notification",
  26. "url": "https://web.hook/"
  27. }`
  28. settingsJSON, _ := simplejson.NewJson([]byte(json))
  29. model := &models.AlertNotification{
  30. Name: "discord_testing",
  31. Type: "discord",
  32. Settings: settingsJSON,
  33. }
  34. not, err := newDiscordNotifier(model)
  35. discordNotifier := not.(*DiscordNotifier)
  36. So(err, ShouldBeNil)
  37. So(discordNotifier.Name, ShouldEqual, "discord_testing")
  38. So(discordNotifier.Type, ShouldEqual, "discord")
  39. So(discordNotifier.Content, ShouldEqual, "@everyone Please check this notification")
  40. So(discordNotifier.WebhookURL, ShouldEqual, "https://web.hook/")
  41. })
  42. })
  43. })
  44. }