alert_notification_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package sqlstore
  2. import (
  3. "fmt"
  4. "testing"
  5. m "github.com/grafana/grafana/pkg/models"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestAlertNotificationSQLAccess(t *testing.T) {
  9. Convey("Testing Alert notification sql access", t, func() {
  10. InitTestDB(t)
  11. var err error
  12. Convey("Alert notifications should be empty", func() {
  13. cmd := &m.GetAlertNotificationQuery{
  14. OrgID: FakeOrgId,
  15. Name: "email",
  16. }
  17. err := AlertNotificationQuery(cmd)
  18. fmt.Printf("errror %v", err)
  19. So(err, ShouldBeNil)
  20. So(len(cmd.Result), ShouldEqual, 0)
  21. })
  22. Convey("Can save Alert Notification", func() {
  23. cmd := &m.CreateAlertNotificationCommand{
  24. Name: "ops",
  25. Type: "email",
  26. }
  27. err = CreateAlertNotificationCommand(cmd)
  28. So(err, ShouldBeNil)
  29. So(cmd.Result.Id, ShouldNotEqual, 0)
  30. Convey("Cannot save Alert Notification with the same name", func() {
  31. err = CreateAlertNotificationCommand(cmd)
  32. So(err, ShouldNotBeNil)
  33. })
  34. Convey("Cannot update alert notification that does not exist", func() {
  35. newCmd := &m.UpdateAlertNotificationCommand{
  36. Name: "NewName",
  37. Type: cmd.Result.Type,
  38. OrgID: cmd.Result.OrgId,
  39. Id: 1337,
  40. }
  41. err = UpdateAlertNotification(newCmd)
  42. So(err, ShouldNotBeNil)
  43. })
  44. Convey("Can update alert notification", func() {
  45. newCmd := &m.UpdateAlertNotificationCommand{
  46. Name: "NewName",
  47. Type: cmd.Result.Type,
  48. OrgID: cmd.Result.OrgId,
  49. Id: cmd.Result.Id,
  50. }
  51. err = UpdateAlertNotification(newCmd)
  52. So(err, ShouldBeNil)
  53. So(newCmd.Result.Name, ShouldEqual, "NewName")
  54. })
  55. })
  56. })
  57. }