alerting_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package sqlstore
  2. import (
  3. "testing"
  4. m "github.com/grafana/grafana/pkg/models"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestAlertingDataAccess(t *testing.T) {
  8. Convey("Testing Alerting data access", t, func() {
  9. InitTestDB(t)
  10. items := []m.Alert{
  11. {
  12. PanelId: 1,
  13. DashboardId: 1,
  14. Query: "Query",
  15. QueryRefId: "A",
  16. WarnLevel: "> 30",
  17. CritLevel: "> 50",
  18. Interval: "10",
  19. Title: "Alerting title",
  20. Description: "Alerting description",
  21. QueryRange: "5m",
  22. Aggregator: "avg",
  23. },
  24. }
  25. cmd := m.SaveAlertsCommand{
  26. Alerts: &items,
  27. DashboardId: 1,
  28. OrgId: 1,
  29. UserId: 1,
  30. }
  31. err := SaveAlerts(&cmd)
  32. Convey("Can create alert", func() {
  33. So(err, ShouldBeNil)
  34. })
  35. Convey("can read properties", func() {
  36. alert, err2 := GetAlertsByDashboard(1, 1)
  37. So(err2, ShouldBeNil)
  38. So(alert.Interval, ShouldEqual, "10")
  39. So(alert.WarnLevel, ShouldEqual, "> 30")
  40. So(alert.CritLevel, ShouldEqual, "> 50")
  41. So(alert.Query, ShouldEqual, "Query")
  42. So(alert.QueryRefId, ShouldEqual, "A")
  43. So(alert.Title, ShouldEqual, "Alerting title")
  44. So(alert.Description, ShouldEqual, "Alerting description")
  45. So(alert.QueryRange, ShouldEqual, "5m")
  46. So(alert.Aggregator, ShouldEqual, "avg")
  47. })
  48. })
  49. }