alert_test.go 896 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package models
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestAlertingModelTest(t *testing.T) {
  8. Convey("Testing Alerting model", t, func() {
  9. json1, _ := simplejson.NewJson([]byte(`{ "field": "value" }`))
  10. json2, _ := simplejson.NewJson([]byte(`{ "field": "value" }`))
  11. rule1 := &Alert{
  12. Expression: json1,
  13. Name: "Namn",
  14. Description: "Description",
  15. }
  16. rule2 := &Alert{
  17. Expression: json2,
  18. Name: "Namn",
  19. Description: "Description",
  20. }
  21. Convey("Testing AlertRule equals", func() {
  22. So(rule1.ContainsUpdates(rule2), ShouldBeFalse)
  23. })
  24. Convey("Changing the expression should contain update", func() {
  25. json2, _ := simplejson.NewJson([]byte(`{ "field": "newValue" }`))
  26. rule1.Expression = json2
  27. So(rule1.ContainsUpdates(rule2), ShouldBeTrue)
  28. })
  29. })
  30. }