alert_state_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package sqlstore
  2. // import (
  3. // "testing"
  4. //
  5. // m "github.com/grafana/grafana/pkg/models"
  6. // . "github.com/smartystreets/goconvey/convey"
  7. // )
  8. //
  9. // func TestAlertingStateAccess(t *testing.T) {
  10. // Convey("Test alerting state changes", t, func() {
  11. // InitTestDB(t)
  12. //
  13. // testDash := insertTestDashboard("dashboard with alerts", 1, "alert")
  14. //
  15. // items := []*m.Alert{
  16. // {
  17. // PanelId: 1,
  18. // DashboardId: testDash.Id,
  19. // OrgId: testDash.OrgId,
  20. // Name: "Alerting title",
  21. // Description: "Alerting description",
  22. // },
  23. // }
  24. //
  25. // cmd := m.SaveAlertsCommand{
  26. // Alerts: items,
  27. // DashboardId: testDash.Id,
  28. // OrgId: 1,
  29. // UserId: 1,
  30. // }
  31. //
  32. // err := SaveAlerts(&cmd)
  33. // So(err, ShouldBeNil)
  34. //
  35. // Convey("Cannot insert invalid states", func() {
  36. // err = SetNewAlertState(&m.UpdateAlertStateCommand{
  37. // AlertId: 1,
  38. // NewState: "maybe ok",
  39. // Info: "Shit just hit the fan",
  40. // })
  41. //
  42. // So(err, ShouldNotBeNil)
  43. // })
  44. //
  45. // Convey("Changes state to alert", func() {
  46. //
  47. // err = SetNewAlertState(&m.UpdateAlertStateCommand{
  48. // AlertId: 1,
  49. // NewState: "CRITICAL",
  50. // Info: "Shit just hit the fan",
  51. // })
  52. //
  53. // Convey("can get new state for alert", func() {
  54. // query := &m.GetAlertByIdQuery{Id: 1}
  55. // err := GetAlertById(query)
  56. // So(err, ShouldBeNil)
  57. // So(query.Result.State, ShouldEqual, "CRITICAL")
  58. // })
  59. //
  60. // Convey("Changes state to ok", func() {
  61. // err = SetNewAlertState(&m.UpdateAlertStateCommand{
  62. // AlertId: 1,
  63. // NewState: "OK",
  64. // Info: "Shit just hit the fan",
  65. // })
  66. //
  67. // Convey("get ok state for alert", func() {
  68. // query := &m.GetAlertByIdQuery{Id: 1}
  69. // err := GetAlertById(query)
  70. // So(err, ShouldBeNil)
  71. // So(query.Result.State, ShouldEqual, "OK")
  72. // })
  73. //
  74. // Convey("should have two event state logs", func() {
  75. // query := &m.GetAlertsStateQuery{
  76. // AlertId: 1,
  77. // OrgId: 1,
  78. // }
  79. //
  80. // err := GetAlertStateLogByAlertId(query)
  81. // So(err, ShouldBeNil)
  82. //
  83. // So(len(*query.Result), ShouldEqual, 2)
  84. // })
  85. //
  86. // Convey("should not get any alerts with critical state", func() {
  87. // query := &m.GetAlertsQuery{
  88. // OrgId: 1,
  89. // State: []string{"Critical", "Warn"},
  90. // }
  91. //
  92. // err := HandleAlertsQuery(query)
  93. // So(err, ShouldBeNil)
  94. // So(len(query.Result), ShouldEqual, 0)
  95. // })
  96. // })
  97. // })
  98. // })
  99. // }