base_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package notifiers
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/grafana/grafana/pkg/components/simplejson"
  6. m "github.com/grafana/grafana/pkg/models"
  7. "github.com/grafana/grafana/pkg/services/alerting"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestBaseNotifier(t *testing.T) {
  11. Convey("Base notifier tests", t, func() {
  12. Convey("default constructor for notifiers", func() {
  13. bJson := simplejson.New()
  14. Convey("can parse false value", func() {
  15. bJson.Set("uploadImage", false)
  16. base := NewNotifierBase(1, false, "name", "email", bJson)
  17. So(base.UploadImage, ShouldBeFalse)
  18. })
  19. Convey("can parse true value", func() {
  20. bJson.Set("uploadImage", true)
  21. base := NewNotifierBase(1, false, "name", "email", bJson)
  22. So(base.UploadImage, ShouldBeTrue)
  23. })
  24. Convey("default value should be true for backwards compatibility", func() {
  25. base := NewNotifierBase(1, false, "name", "email", bJson)
  26. So(base.UploadImage, ShouldBeTrue)
  27. })
  28. })
  29. Convey("should notify", func() {
  30. Convey("pending -> ok", func() {
  31. context := alerting.NewEvalContext(context.TODO(), &alerting.Rule{
  32. State: m.AlertStatePending,
  33. })
  34. context.Rule.State = m.AlertStateOK
  35. So(defaultShouldNotify(context), ShouldBeFalse)
  36. })
  37. Convey("ok -> alerting", func() {
  38. context := alerting.NewEvalContext(context.TODO(), &alerting.Rule{
  39. State: m.AlertStateOK,
  40. })
  41. context.Rule.State = m.AlertStateAlerting
  42. So(defaultShouldNotify(context), ShouldBeTrue)
  43. })
  44. })
  45. })
  46. }