alert_notification_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package sqlstore
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/grafana/grafana/pkg/components/simplejson"
  6. m "github.com/grafana/grafana/pkg/models"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestAlertNotificationSQLAccess(t *testing.T) {
  10. Convey("Testing Alert notification sql access", t, func() {
  11. InitTestDB(t)
  12. var err error
  13. Convey("Alert notifications should be empty", func() {
  14. cmd := &m.GetAlertNotificationQuery{
  15. OrgID: FakeOrgId,
  16. Name: "email",
  17. }
  18. err := AlertNotificationQuery(cmd)
  19. fmt.Printf("errror %v", err)
  20. So(err, ShouldBeNil)
  21. So(len(cmd.Result), ShouldEqual, 0)
  22. })
  23. Convey("Can save Alert Notification", func() {
  24. cmd := &m.CreateAlertNotificationCommand{
  25. Name: "ops",
  26. Type: "email",
  27. OrgID: 1,
  28. Settings: simplejson.New(),
  29. }
  30. err = CreateAlertNotificationCommand(cmd)
  31. So(err, ShouldBeNil)
  32. So(cmd.Result.Id, ShouldNotEqual, 0)
  33. So(cmd.Result.OrgId, ShouldNotEqual, 0)
  34. So(cmd.Result.Type, ShouldEqual, "email")
  35. Convey("Cannot save Alert Notification with the same name", func() {
  36. err = CreateAlertNotificationCommand(cmd)
  37. So(err, ShouldNotBeNil)
  38. })
  39. Convey("Can update alert notification", func() {
  40. newCmd := &m.UpdateAlertNotificationCommand{
  41. Name: "NewName",
  42. Type: "webhook",
  43. OrgID: cmd.Result.OrgId,
  44. Settings: simplejson.New(),
  45. Id: cmd.Result.Id,
  46. }
  47. err := UpdateAlertNotification(newCmd)
  48. So(err, ShouldBeNil)
  49. So(newCmd.Result.Name, ShouldEqual, "NewName")
  50. })
  51. })
  52. Convey("Can search using an array of ids", func() {
  53. So(CreateAlertNotificationCommand(&m.CreateAlertNotificationCommand{
  54. Name: "ops2",
  55. Type: "email",
  56. OrgID: 1,
  57. Settings: simplejson.New(),
  58. }), ShouldBeNil)
  59. So(CreateAlertNotificationCommand(&m.CreateAlertNotificationCommand{
  60. Name: "slack",
  61. Type: "webhook",
  62. OrgID: 1,
  63. Settings: simplejson.New(),
  64. }), ShouldBeNil)
  65. Convey("search", func() {
  66. query := &m.GetAlertNotificationQuery{
  67. Ids: []int64{1, 2, 3},
  68. OrgID: 1,
  69. }
  70. err := AlertNotificationQuery(query)
  71. So(err, ShouldBeNil)
  72. So(len(query.Result), ShouldEqual, 2)
  73. })
  74. })
  75. })
  76. }