dingding_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 := `{ "url": "https://www.google.com" }`
  23. settingsJSON, _ := simplejson.NewJson([]byte(json))
  24. model := &m.AlertNotification{
  25. Name: "dingding_testing",
  26. Type: "dingding",
  27. Settings: settingsJSON,
  28. }
  29. not, err := NewDingDingNotifier(model)
  30. notifier := not.(*DingDingNotifier)
  31. So(err, ShouldBeNil)
  32. So(notifier.Name, ShouldEqual, "dingding_testing")
  33. So(notifier.Type, ShouldEqual, "dingding")
  34. So(notifier.Url, ShouldEqual, "https://www.google.com")
  35. })
  36. })
  37. }