googlechat_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 TestGoogleChatNotifier(t *testing.T) {
  9. Convey("Google Hangouts Chat 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: "ops",
  16. Type: "googlechat",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewGoogleChatNotifier(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 := &m.AlertNotification{
  29. Name: "ops",
  30. Type: "googlechat",
  31. Settings: settingsJSON,
  32. }
  33. not, err := NewGoogleChatNotifier(model)
  34. webhookNotifier := not.(*GoogleChatNotifier)
  35. So(err, ShouldBeNil)
  36. So(webhookNotifier.Name, ShouldEqual, "ops")
  37. So(webhookNotifier.Type, ShouldEqual, "googlechat")
  38. So(webhookNotifier.Url, ShouldEqual, "http://google.com")
  39. })
  40. })
  41. })
  42. }