mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
wip: impl so that get alertstate also creates it if it does not exist
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -14,55 +13,57 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Convey("Testing Alert notification sql access", t, func() {
|
||||
InitTestDB(t)
|
||||
|
||||
Convey("Alert notification state", func() {
|
||||
var alertId int64 = 7
|
||||
var orgId int64 = 5
|
||||
var notifierId int64 = 10
|
||||
//Convey("Alert notification state", func() {
|
||||
//var alertId int64 = 7
|
||||
//var orgId int64 = 5
|
||||
//var notifierId int64 = 10
|
||||
|
||||
Convey("Getting no existant state returns error", func() {
|
||||
query := &models.GetNotificationStateQuery{AlertId: alertId, OrgId: orgId, NotifierId: notifierId}
|
||||
err := GetAlertNotificationState(context.Background(), query)
|
||||
So(err, ShouldEqual, models.ErrAlertNotificationStateNotFound)
|
||||
})
|
||||
//Convey("Getting no existant state returns error", func() {
|
||||
// query := &models.GetNotificationStateQuery{AlertId: alertId, OrgId: orgId, NotifierId: notifierId}
|
||||
// err := GetAlertNotificationState(context.Background(), query)
|
||||
// So(err, ShouldEqual, models.ErrAlertNotificationStateNotFound)
|
||||
//})
|
||||
|
||||
Convey("Can insert new state for alert notifier", func() {
|
||||
createCmd := &models.InsertAlertNotificationCommand{
|
||||
AlertId: alertId,
|
||||
NotifierId: notifierId,
|
||||
OrgId: orgId,
|
||||
SentAt: 1,
|
||||
State: models.AlertNotificationStateCompleted,
|
||||
}
|
||||
|
||||
err := InsertAlertNotificationState(context.Background(), createCmd)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = InsertAlertNotificationState(context.Background(), createCmd)
|
||||
So(err, ShouldEqual, models.ErrAlertNotificationStateAlreadyExist)
|
||||
|
||||
Convey("should be able to update alert notifier state", func() {
|
||||
updateCmd := &models.SetAlertNotificationStateToPendingCommand{
|
||||
Id: 1,
|
||||
SentAt: 1,
|
||||
Version: 0,
|
||||
}
|
||||
|
||||
err := SetAlertNotificationStateToPendingCommand(context.Background(), updateCmd)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("should not be able to set pending on old version", func() {
|
||||
err = SetAlertNotificationStateToPendingCommand(context.Background(), updateCmd)
|
||||
So(err, ShouldEqual, models.ErrAlertNotificationStateVersionConflict)
|
||||
})
|
||||
|
||||
Convey("should be able to set state to completed", func() {
|
||||
cmd := &models.SetAlertNotificationStateToCompleteCommand{Id: 1}
|
||||
err = SetAlertNotificationStateToCompleteCommand(context.Background(), cmd)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
//Convey("Can insert new state for alert notifier", func() {
|
||||
// createCmd := &models.InsertAlertNotificationCommand{
|
||||
// AlertId: alertId,
|
||||
// NotifierId: notifierId,
|
||||
// OrgId: orgId,
|
||||
// SentAt: 1,
|
||||
// State: models.AlertNotificationStateCompleted,
|
||||
// }
|
||||
//
|
||||
// err := InsertAlertNotificationState(context.Background(), createCmd)
|
||||
// So(err, ShouldBeNil)
|
||||
//
|
||||
// err = InsertAlertNotificationState(context.Background(), createCmd)
|
||||
// So(err, ShouldEqual, models.ErrAlertNotificationStateAlreadyExist)
|
||||
//
|
||||
// Convey("should be able to update alert notifier state", func() {
|
||||
// updateCmd := &models.SetAlertNotificationStateToPendingCommand{
|
||||
// State: models.AlertNotificationState{
|
||||
// Id: 1,
|
||||
// SentAt: 1,
|
||||
// Version: 0,
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// err := SetAlertNotificationStateToPendingCommand(context.Background(), updateCmd)
|
||||
// So(err, ShouldBeNil)
|
||||
//
|
||||
// Convey("should not be able to set pending on old version", func() {
|
||||
// err = SetAlertNotificationStateToPendingCommand(context.Background(), updateCmd)
|
||||
// So(err, ShouldEqual, models.ErrAlertNotificationStateVersionConflict)
|
||||
// })
|
||||
//
|
||||
// Convey("should be able to set state to completed", func() {
|
||||
// cmd := &models.SetAlertNotificationStateToCompleteCommand{Id: 1}
|
||||
// err = SetAlertNotificationStateToCompleteCommand(context.Background(), cmd)
|
||||
// So(err, ShouldBeNil)
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
//})
|
||||
|
||||
Convey("Alert notifications should be empty", func() {
|
||||
cmd := &models.GetAlertNotificationsQuery{
|
||||
|
||||
Reference in New Issue
Block a user