add context in the alert_notification (#41307)
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func (ss *SQLStore) DeleteAlertNotification(cmd *models.DeleteAlertNotificationCommand) error {
|
||||
func (ss *SQLStore) DeleteAlertNotification(ctx context.Context, cmd *models.DeleteAlertNotificationCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
sql := "DELETE FROM alert_notification WHERE alert_notification.org_id = ? AND alert_notification.id = ?"
|
||||
res, err := sess.Exec(sql, cmd.OrgId, cmd.Id)
|
||||
@@ -37,9 +37,9 @@ func (ss *SQLStore) DeleteAlertNotification(cmd *models.DeleteAlertNotificationC
|
||||
})
|
||||
}
|
||||
|
||||
func (ss *SQLStore) DeleteAlertNotificationWithUid(cmd *models.DeleteAlertNotificationWithUidCommand) error {
|
||||
func (ss *SQLStore) DeleteAlertNotificationWithUid(ctx context.Context, cmd *models.DeleteAlertNotificationWithUidCommand) error {
|
||||
existingNotification := &models.GetAlertNotificationsWithUidQuery{OrgId: cmd.OrgId, Uid: cmd.Uid}
|
||||
if err := getAlertNotificationWithUidInternal(existingNotification, newSession(context.Background())); err != nil {
|
||||
if err := getAlertNotificationWithUidInternal(ctx, existingNotification, newSession(context.Background())); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -52,22 +52,22 @@ func (ss *SQLStore) DeleteAlertNotificationWithUid(cmd *models.DeleteAlertNotifi
|
||||
Id: existingNotification.Result.Id,
|
||||
OrgId: existingNotification.Result.OrgId,
|
||||
}
|
||||
if err := bus.Dispatch(deleteCommand); err != nil {
|
||||
if err := bus.DispatchCtx(ctx, deleteCommand); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ss *SQLStore) GetAlertNotifications(query *models.GetAlertNotificationsQuery) error {
|
||||
return getAlertNotificationInternal(query, newSession(context.Background()))
|
||||
func (ss *SQLStore) GetAlertNotifications(ctx context.Context, query *models.GetAlertNotificationsQuery) error {
|
||||
return getAlertNotificationInternal(ctx, query, newSession(context.Background()))
|
||||
}
|
||||
|
||||
func (ss *SQLStore) addAlertNotificationUidByIdHandler() {
|
||||
bus.AddHandler("sql", ss.GetAlertNotificationUidWithId)
|
||||
bus.AddHandlerCtx("sql", ss.GetAlertNotificationUidWithId)
|
||||
}
|
||||
|
||||
func (ss *SQLStore) GetAlertNotificationUidWithId(query *models.GetAlertNotificationUidQuery) error {
|
||||
func (ss *SQLStore) GetAlertNotificationUidWithId(ctx context.Context, query *models.GetAlertNotificationUidQuery) error {
|
||||
cacheKey := newAlertNotificationUidCacheKey(query.OrgId, query.Id)
|
||||
|
||||
if cached, found := ss.CacheService.Get(cacheKey); found {
|
||||
@@ -75,7 +75,7 @@ func (ss *SQLStore) GetAlertNotificationUidWithId(query *models.GetAlertNotifica
|
||||
return nil
|
||||
}
|
||||
|
||||
err := getAlertNotificationUidInternal(query, newSession(context.Background()))
|
||||
err := getAlertNotificationUidInternal(ctx, query, newSession(context.Background()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -89,11 +89,11 @@ func newAlertNotificationUidCacheKey(orgID, notificationId int64) string {
|
||||
return fmt.Sprintf("notification-uid-by-org-%d-and-id-%d", orgID, notificationId)
|
||||
}
|
||||
|
||||
func (ss *SQLStore) GetAlertNotificationsWithUid(query *models.GetAlertNotificationsWithUidQuery) error {
|
||||
return getAlertNotificationWithUidInternal(query, newSession(context.Background()))
|
||||
func (ss *SQLStore) GetAlertNotificationsWithUid(ctx context.Context, query *models.GetAlertNotificationsWithUidQuery) error {
|
||||
return getAlertNotificationWithUidInternal(ctx, query, newSession(context.Background()))
|
||||
}
|
||||
|
||||
func (ss *SQLStore) GetAllAlertNotifications(query *models.GetAllAlertNotificationsQuery) error {
|
||||
func (ss *SQLStore) GetAllAlertNotifications(ctx context.Context, query *models.GetAllAlertNotificationsQuery) error {
|
||||
results := make([]*models.AlertNotification, 0)
|
||||
if err := x.Where("org_id = ?", query.OrgId).Asc("name").Find(&results); err != nil {
|
||||
return err
|
||||
@@ -103,7 +103,7 @@ func (ss *SQLStore) GetAllAlertNotifications(query *models.GetAllAlertNotificati
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ss *SQLStore) GetAlertNotificationsWithUidToSend(query *models.GetAlertNotificationsWithUidToSendQuery) error {
|
||||
func (ss *SQLStore) GetAlertNotificationsWithUidToSend(ctx context.Context, query *models.GetAlertNotificationsWithUidToSendQuery) error {
|
||||
var sql bytes.Buffer
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
@@ -147,7 +147,7 @@ func (ss *SQLStore) GetAlertNotificationsWithUidToSend(query *models.GetAlertNot
|
||||
return nil
|
||||
}
|
||||
|
||||
func getAlertNotificationUidInternal(query *models.GetAlertNotificationUidQuery, sess *DBSession) error {
|
||||
func getAlertNotificationUidInternal(ctx context.Context, query *models.GetAlertNotificationUidQuery, sess *DBSession) error {
|
||||
var sql bytes.Buffer
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
@@ -176,7 +176,7 @@ func getAlertNotificationUidInternal(query *models.GetAlertNotificationUidQuery,
|
||||
return nil
|
||||
}
|
||||
|
||||
func getAlertNotificationInternal(query *models.GetAlertNotificationsQuery, sess *DBSession) error {
|
||||
func getAlertNotificationInternal(ctx context.Context, query *models.GetAlertNotificationsQuery, sess *DBSession) error {
|
||||
var sql bytes.Buffer
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
@@ -226,7 +226,7 @@ func getAlertNotificationInternal(query *models.GetAlertNotificationsQuery, sess
|
||||
return nil
|
||||
}
|
||||
|
||||
func getAlertNotificationWithUidInternal(query *models.GetAlertNotificationsWithUidQuery, sess *DBSession) error {
|
||||
func getAlertNotificationWithUidInternal(ctx context.Context, query *models.GetAlertNotificationsWithUidQuery, sess *DBSession) error {
|
||||
var sql bytes.Buffer
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
@@ -264,10 +264,10 @@ func getAlertNotificationWithUidInternal(query *models.GetAlertNotificationsWith
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ss *SQLStore) CreateAlertNotificationCommand(cmd *models.CreateAlertNotificationCommand) error {
|
||||
func (ss *SQLStore) CreateAlertNotificationCommand(ctx context.Context, cmd *models.CreateAlertNotificationCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
if cmd.Uid == "" {
|
||||
uid, uidGenerationErr := generateNewAlertNotificationUid(sess, cmd.OrgId)
|
||||
uid, uidGenerationErr := generateNewAlertNotificationUid(ctx, sess, cmd.OrgId)
|
||||
if uidGenerationErr != nil {
|
||||
return uidGenerationErr
|
||||
}
|
||||
@@ -275,7 +275,7 @@ func (ss *SQLStore) CreateAlertNotificationCommand(cmd *models.CreateAlertNotifi
|
||||
cmd.Uid = uid
|
||||
}
|
||||
existingQuery := &models.GetAlertNotificationsWithUidQuery{OrgId: cmd.OrgId, Uid: cmd.Uid}
|
||||
err := getAlertNotificationWithUidInternal(existingQuery, sess)
|
||||
err := getAlertNotificationWithUidInternal(ctx, existingQuery, sess)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -287,7 +287,7 @@ func (ss *SQLStore) CreateAlertNotificationCommand(cmd *models.CreateAlertNotifi
|
||||
|
||||
// check if name exists
|
||||
sameNameQuery := &models.GetAlertNotificationsQuery{OrgId: cmd.OrgId, Name: cmd.Name}
|
||||
if err := getAlertNotificationInternal(sameNameQuery, sess); err != nil {
|
||||
if err := getAlertNotificationInternal(ctx, sameNameQuery, sess); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ func (ss *SQLStore) CreateAlertNotificationCommand(cmd *models.CreateAlertNotifi
|
||||
})
|
||||
}
|
||||
|
||||
func generateNewAlertNotificationUid(sess *DBSession, orgId int64) (string, error) {
|
||||
func generateNewAlertNotificationUid(ctx context.Context, sess *DBSession, orgId int64) (string, error) {
|
||||
for i := 0; i < 3; i++ {
|
||||
uid := util.GenerateShortUID()
|
||||
exists, err := sess.Where("org_id=? AND uid=?", orgId, uid).Get(&models.AlertNotification{})
|
||||
@@ -354,7 +354,7 @@ func generateNewAlertNotificationUid(sess *DBSession, orgId int64) (string, erro
|
||||
return "", models.ErrAlertNotificationFailedGenerateUniqueUid
|
||||
}
|
||||
|
||||
func (ss *SQLStore) UpdateAlertNotification(cmd *models.UpdateAlertNotificationCommand) error {
|
||||
func (ss *SQLStore) UpdateAlertNotification(ctx context.Context, cmd *models.UpdateAlertNotificationCommand) error {
|
||||
return inTransaction(func(sess *DBSession) (err error) {
|
||||
current := models.AlertNotification{}
|
||||
|
||||
@@ -368,7 +368,7 @@ func (ss *SQLStore) UpdateAlertNotification(cmd *models.UpdateAlertNotificationC
|
||||
|
||||
// check if name exists
|
||||
sameNameQuery := &models.GetAlertNotificationsQuery{OrgId: cmd.OrgId, Name: cmd.Name}
|
||||
if err := getAlertNotificationInternal(sameNameQuery, sess); err != nil {
|
||||
if err := getAlertNotificationInternal(ctx, sameNameQuery, sess); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -422,10 +422,10 @@ func (ss *SQLStore) UpdateAlertNotification(cmd *models.UpdateAlertNotificationC
|
||||
})
|
||||
}
|
||||
|
||||
func (ss *SQLStore) UpdateAlertNotificationWithUid(cmd *models.UpdateAlertNotificationWithUidCommand) error {
|
||||
func (ss *SQLStore) UpdateAlertNotificationWithUid(ctx context.Context, cmd *models.UpdateAlertNotificationWithUidCommand) error {
|
||||
getAlertNotificationWithUidQuery := &models.GetAlertNotificationsWithUidQuery{OrgId: cmd.OrgId, Uid: cmd.Uid}
|
||||
|
||||
if err := getAlertNotificationWithUidInternal(getAlertNotificationWithUidQuery, newSession(context.Background())); err != nil {
|
||||
if err := getAlertNotificationWithUidInternal(ctx, getAlertNotificationWithUidQuery, newSession(context.Background())); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ func (ss *SQLStore) UpdateAlertNotificationWithUid(cmd *models.UpdateAlertNotifi
|
||||
OrgId: cmd.OrgId,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(updateNotification); err != nil {
|
||||
if err := bus.DispatchCtx(ctx, updateNotification); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -532,7 +532,7 @@ func (ss *SQLStore) GetOrCreateAlertNotificationState(ctx context.Context, cmd *
|
||||
return inTransactionCtx(ctx, func(sess *DBSession) error {
|
||||
nj := &models.AlertNotificationState{}
|
||||
|
||||
exist, err := getAlertNotificationState(sess, cmd, nj)
|
||||
exist, err := getAlertNotificationState(ctx, sess, cmd, nj)
|
||||
|
||||
// if exists, return it, otherwise create it with default values
|
||||
if err != nil {
|
||||
@@ -554,7 +554,7 @@ func (ss *SQLStore) GetOrCreateAlertNotificationState(ctx context.Context, cmd *
|
||||
|
||||
if _, err := sess.Insert(notificationState); err != nil {
|
||||
if dialect.IsUniqueConstraintViolation(err) {
|
||||
exist, err = getAlertNotificationState(sess, cmd, nj)
|
||||
exist, err = getAlertNotificationState(ctx, sess, cmd, nj)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -576,7 +576,7 @@ func (ss *SQLStore) GetOrCreateAlertNotificationState(ctx context.Context, cmd *
|
||||
})
|
||||
}
|
||||
|
||||
func getAlertNotificationState(sess *DBSession, cmd *models.GetOrCreateNotificationStateQuery, nj *models.AlertNotificationState) (bool, error) {
|
||||
func getAlertNotificationState(ctx context.Context, sess *DBSession, cmd *models.GetOrCreateNotificationStateQuery, nj *models.AlertNotificationState) (bool, error) {
|
||||
return sess.
|
||||
Where("alert_notification_state.org_id = ?", cmd.OrgId).
|
||||
Where("alert_notification_state.alert_id = ?", cmd.AlertId).
|
||||
|
||||
@@ -23,8 +23,8 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
sqlStore := InitTestDB(t)
|
||||
|
||||
// Set up bus handlers
|
||||
bus.AddHandler("deleteAlertNotification", func(cmd *models.DeleteAlertNotificationCommand) error {
|
||||
return sqlStore.DeleteAlertNotification(cmd)
|
||||
bus.AddHandlerCtx("deleteAlertNotification", func(ctx context.Context, cmd *models.DeleteAlertNotificationCommand) error {
|
||||
return sqlStore.DeleteAlertNotification(ctx, cmd)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Name: "email",
|
||||
}
|
||||
|
||||
err := sqlStore.GetAlertNotifications(cmd)
|
||||
err := sqlStore.GetAlertNotifications(context.Background(), cmd)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, cmd.Result)
|
||||
})
|
||||
@@ -175,14 +175,14 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("and missing frequency", func(t *testing.T) {
|
||||
err := sqlStore.CreateAlertNotificationCommand(cmd)
|
||||
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
|
||||
require.Equal(t, models.ErrNotificationFrequencyNotFound, err)
|
||||
})
|
||||
|
||||
t.Run("invalid frequency", func(t *testing.T) {
|
||||
cmd.Frequency = "invalid duration"
|
||||
|
||||
err := sqlStore.CreateAlertNotificationCommand(cmd)
|
||||
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
|
||||
require.True(t, regexp.MustCompile(`^time: invalid duration "?invalid duration"?$`).MatchString(
|
||||
err.Error()))
|
||||
})
|
||||
@@ -198,7 +198,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Settings: simplejson.New(),
|
||||
}
|
||||
|
||||
err := sqlStore.CreateAlertNotificationCommand(cmd)
|
||||
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
|
||||
require.Nil(t, err)
|
||||
|
||||
updateCmd := &models.UpdateAlertNotificationCommand{
|
||||
@@ -207,14 +207,14 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("and missing frequency", func(t *testing.T) {
|
||||
err := sqlStore.UpdateAlertNotification(updateCmd)
|
||||
err := sqlStore.UpdateAlertNotification(context.Background(), updateCmd)
|
||||
require.Equal(t, models.ErrNotificationFrequencyNotFound, err)
|
||||
})
|
||||
|
||||
t.Run("invalid frequency", func(t *testing.T) {
|
||||
updateCmd.Frequency = "invalid duration"
|
||||
|
||||
err := sqlStore.UpdateAlertNotification(updateCmd)
|
||||
err := sqlStore.UpdateAlertNotification(context.Background(), updateCmd)
|
||||
require.Error(t, err)
|
||||
require.True(t, regexp.MustCompile(`^time: invalid duration "?invalid duration"?$`).MatchString(
|
||||
err.Error()))
|
||||
@@ -232,7 +232,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Settings: simplejson.New(),
|
||||
}
|
||||
|
||||
err := sqlStore.CreateAlertNotificationCommand(cmd)
|
||||
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
|
||||
require.Nil(t, err)
|
||||
require.NotEqual(t, 0, cmd.Result.Id)
|
||||
require.NotEqual(t, 0, cmd.Result.OrgId)
|
||||
@@ -242,7 +242,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
require.NotEmpty(t, cmd.Result.Uid)
|
||||
|
||||
t.Run("Cannot save Alert Notification with the same name", func(t *testing.T) {
|
||||
err = sqlStore.CreateAlertNotificationCommand(cmd)
|
||||
err = sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("Cannot save Alert Notification with the same name and another uid", func(t *testing.T) {
|
||||
@@ -255,7 +255,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Settings: cmd.Settings,
|
||||
Uid: "notifier1",
|
||||
}
|
||||
err = sqlStore.CreateAlertNotificationCommand(anotherUidCmd)
|
||||
err = sqlStore.CreateAlertNotificationCommand(context.Background(), anotherUidCmd)
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("Can save Alert Notification with another name and another uid", func(t *testing.T) {
|
||||
@@ -268,7 +268,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Settings: cmd.Settings,
|
||||
Uid: "notifier2",
|
||||
}
|
||||
err = sqlStore.CreateAlertNotificationCommand(anotherUidCmd)
|
||||
err = sqlStore.CreateAlertNotificationCommand(context.Background(), anotherUidCmd)
|
||||
require.Nil(t, err)
|
||||
})
|
||||
|
||||
@@ -283,7 +283,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Settings: simplejson.New(),
|
||||
Id: cmd.Result.Id,
|
||||
}
|
||||
err := sqlStore.UpdateAlertNotification(newCmd)
|
||||
err := sqlStore.UpdateAlertNotification(context.Background(), newCmd)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "NewName", newCmd.Result.Name)
|
||||
require.Equal(t, 60*time.Second, newCmd.Result.Frequency)
|
||||
@@ -299,7 +299,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Settings: simplejson.New(),
|
||||
Id: cmd.Result.Id,
|
||||
}
|
||||
err := sqlStore.UpdateAlertNotification(newCmd)
|
||||
err := sqlStore.UpdateAlertNotification(context.Background(), newCmd)
|
||||
require.Nil(t, err)
|
||||
require.False(t, newCmd.Result.SendReminder)
|
||||
})
|
||||
@@ -314,11 +314,11 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
|
||||
otherOrg := models.CreateAlertNotificationCommand{Name: "default", Type: "email", OrgId: 2, SendReminder: true, Frequency: "10s", Settings: simplejson.New()}
|
||||
|
||||
require.Nil(t, sqlStore.CreateAlertNotificationCommand(&cmd1))
|
||||
require.Nil(t, sqlStore.CreateAlertNotificationCommand(&cmd2))
|
||||
require.Nil(t, sqlStore.CreateAlertNotificationCommand(&cmd3))
|
||||
require.Nil(t, sqlStore.CreateAlertNotificationCommand(&cmd4))
|
||||
require.Nil(t, sqlStore.CreateAlertNotificationCommand(&otherOrg))
|
||||
require.Nil(t, sqlStore.CreateAlertNotificationCommand(context.Background(), &cmd1))
|
||||
require.Nil(t, sqlStore.CreateAlertNotificationCommand(context.Background(), &cmd2))
|
||||
require.Nil(t, sqlStore.CreateAlertNotificationCommand(context.Background(), &cmd3))
|
||||
require.Nil(t, sqlStore.CreateAlertNotificationCommand(context.Background(), &cmd4))
|
||||
require.Nil(t, sqlStore.CreateAlertNotificationCommand(context.Background(), &otherOrg))
|
||||
|
||||
t.Run("search", func(t *testing.T) {
|
||||
query := &models.GetAlertNotificationsWithUidToSendQuery{
|
||||
@@ -326,7 +326,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
OrgId: 1,
|
||||
}
|
||||
|
||||
err := sqlStore.GetAlertNotificationsWithUidToSend(query)
|
||||
err := sqlStore.GetAlertNotificationsWithUidToSend(context.Background(), query)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 3, len(query.Result))
|
||||
})
|
||||
@@ -336,7 +336,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
OrgId: 1,
|
||||
}
|
||||
|
||||
err := sqlStore.GetAllAlertNotifications(query)
|
||||
err := sqlStore.GetAllAlertNotifications(context.Background(), query)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 4, len(query.Result))
|
||||
require.Equal(t, cmd4.Name, query.Result[0].Name)
|
||||
@@ -351,7 +351,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
ss := InitTestDB(t)
|
||||
|
||||
notification := &models.CreateAlertNotificationCommand{Uid: "aNotificationUid", OrgId: 1, Name: "aNotificationUid"}
|
||||
err := sqlStore.CreateAlertNotificationCommand(notification)
|
||||
err := sqlStore.CreateAlertNotificationCommand(context.Background(), notification)
|
||||
require.Nil(t, err)
|
||||
|
||||
byUidQuery := &models.GetAlertNotificationsWithUidQuery{
|
||||
@@ -359,7 +359,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
OrgId: notification.OrgId,
|
||||
}
|
||||
|
||||
notificationByUidErr := sqlStore.GetAlertNotificationsWithUid(byUidQuery)
|
||||
notificationByUidErr := sqlStore.GetAlertNotificationsWithUid(context.Background(), byUidQuery)
|
||||
require.Nil(t, notificationByUidErr)
|
||||
|
||||
t.Run("Can cache notification Uid", func(t *testing.T) {
|
||||
@@ -374,7 +374,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
require.False(t, foundBeforeCaching)
|
||||
require.Nil(t, resultBeforeCaching)
|
||||
|
||||
notificationByIdErr := ss.GetAlertNotificationUidWithId(byIdQuery)
|
||||
notificationByIdErr := ss.GetAlertNotificationUidWithId(context.Background(), byIdQuery)
|
||||
require.Nil(t, notificationByIdErr)
|
||||
|
||||
resultAfterCaching, foundAfterCaching := ss.CacheService.Get(cacheKey)
|
||||
@@ -390,7 +390,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
cacheKey := newAlertNotificationUidCacheKey(query.OrgId, query.Id)
|
||||
ss.CacheService.Set(cacheKey, "a-cached-uid", -1)
|
||||
|
||||
err := ss.GetAlertNotificationUidWithId(query)
|
||||
err := ss.GetAlertNotificationUidWithId(context.Background(), query)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "a-cached-uid", query.Result)
|
||||
})
|
||||
@@ -401,7 +401,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
OrgId: 100,
|
||||
}
|
||||
|
||||
err := ss.GetAlertNotificationUidWithId(query)
|
||||
err := ss.GetAlertNotificationUidWithId(context.Background(), query)
|
||||
require.Equal(t, "", query.Result)
|
||||
require.Error(t, err)
|
||||
require.True(t, errors.Is(err, models.ErrAlertNotificationFailedTranslateUniqueID))
|
||||
@@ -425,7 +425,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Settings: simplejson.New(),
|
||||
Id: 1,
|
||||
}
|
||||
err := sqlStore.UpdateAlertNotification(updateCmd)
|
||||
err := sqlStore.UpdateAlertNotification(context.Background(), updateCmd)
|
||||
require.Equal(t, models.ErrAlertNotificationNotFound, err)
|
||||
|
||||
t.Run("using UID", func(t *testing.T) {
|
||||
@@ -440,7 +440,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Uid: "uid",
|
||||
NewUid: "newUid",
|
||||
}
|
||||
err := sqlStore.UpdateAlertNotificationWithUid(updateWithUidCmd)
|
||||
err := sqlStore.UpdateAlertNotificationWithUid(context.Background(), updateWithUidCmd)
|
||||
require.Equal(t, models.ErrAlertNotificationNotFound, err)
|
||||
})
|
||||
})
|
||||
@@ -455,18 +455,18 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Settings: simplejson.New(),
|
||||
}
|
||||
|
||||
err := sqlStore.CreateAlertNotificationCommand(cmd)
|
||||
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
|
||||
require.Nil(t, err)
|
||||
|
||||
deleteCmd := &models.DeleteAlertNotificationCommand{
|
||||
Id: cmd.Result.Id,
|
||||
OrgId: 1,
|
||||
}
|
||||
err = sqlStore.DeleteAlertNotification(deleteCmd)
|
||||
err = sqlStore.DeleteAlertNotification(context.Background(), deleteCmd)
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("using UID", func(t *testing.T) {
|
||||
err := sqlStore.CreateAlertNotificationCommand(cmd)
|
||||
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
|
||||
require.Nil(t, err)
|
||||
|
||||
deleteWithUidCmd := &models.DeleteAlertNotificationWithUidCommand{
|
||||
@@ -474,7 +474,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
OrgId: 1,
|
||||
}
|
||||
|
||||
err = sqlStore.DeleteAlertNotificationWithUid(deleteWithUidCmd)
|
||||
err = sqlStore.DeleteAlertNotificationWithUid(context.Background(), deleteWithUidCmd)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, cmd.Result.Id, deleteWithUidCmd.DeletedAlertNotificationId)
|
||||
})
|
||||
@@ -486,7 +486,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Id: 1,
|
||||
OrgId: 1,
|
||||
}
|
||||
err := sqlStore.DeleteAlertNotification(deleteCmd)
|
||||
err := sqlStore.DeleteAlertNotification(context.Background(), deleteCmd)
|
||||
require.Equal(t, models.ErrAlertNotificationNotFound, err)
|
||||
|
||||
t.Run("using UID", func(t *testing.T) {
|
||||
@@ -494,7 +494,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
Uid: "uid",
|
||||
OrgId: 1,
|
||||
}
|
||||
err = sqlStore.DeleteAlertNotificationWithUid(deleteWithUidCmd)
|
||||
err = sqlStore.DeleteAlertNotificationWithUid(context.Background(), deleteWithUidCmd)
|
||||
require.Equal(t, models.ErrAlertNotificationNotFound, err)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user