dingding_test.go 1.2 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 TestDingDingNotifier(t *testing.T) {
  9. Convey("Dingding 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: "dingding_testing",
  15. Type: "dingding",
  16. Settings: settingsJSON,
  17. }
  18. _, err := NewDingDingNotifier(model)
  19. So(err, ShouldNotBeNil)
  20. })
  21. Convey("settings should trigger incident", func() {
  22. json := `
  23. {
  24. "url": "https://www.google.com"
  25. }`
  26. settingsJSON, _ := simplejson.NewJson([]byte(json))
  27. model := &m.AlertNotification{
  28. Name: "dingding_testing",
  29. Type: "dingding",
  30. Settings: settingsJSON,
  31. }
  32. not, err := NewDingDingNotifier(model)
  33. notifier := not.(*DingDingNotifier)
  34. So(err, ShouldBeNil)
  35. So(notifier.Name, ShouldEqual, "dingding_testing")
  36. So(notifier.Type, ShouldEqual, "dingding")
  37. So(notifier.Url, ShouldEqual, "https://www.google.com")
  38. })
  39. })
  40. }