Chore: Sql store split for legacy alerting (#52901)
Moves ~20 sqlstore methods for legacy alerting out of sqlstore (sqlstore.Store interface) and into alerting.
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/alerting"
|
||||
"github.com/grafana/grafana/pkg/services/alerting/notifiers"
|
||||
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
|
||||
"github.com/grafana/grafana/pkg/services/notifications"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -31,6 +32,7 @@ var (
|
||||
|
||||
func TestNotificationAsConfig(t *testing.T) {
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var ns *alerting.AlertNotificationService
|
||||
logger := log.New("fake.log")
|
||||
|
||||
encryptionService := encryptionservice.SetupTestService(t)
|
||||
@@ -38,6 +40,8 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
t.Run("Testing notification as configuration", func(t *testing.T) {
|
||||
setup := func() {
|
||||
sqlStore = sqlstore.InitTestDB(t)
|
||||
nm := ¬ifications.NotificationService{}
|
||||
ns = alerting.ProvideService(sqlStore, encryptionService, nm)
|
||||
|
||||
for i := 1; i < 5; i++ {
|
||||
orgCommand := models.CreateOrgCommand{Name: fmt.Sprintf("Main Org. %v", i)}
|
||||
@@ -158,11 +162,11 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
Uid: "notifier1",
|
||||
Type: "slack",
|
||||
}
|
||||
err := sqlStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
|
||||
err := ns.SQLStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, existingNotificationCmd.Result)
|
||||
notificationsQuery := models.GetAllAlertNotificationsQuery{OrgId: 1}
|
||||
err = sqlStore.GetAllAlertNotifications(context.Background(), ¬ificationsQuery)
|
||||
err = ns.SQLStore.GetAllAlertNotifications(context.Background(), ¬ificationsQuery)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, notificationsQuery.Result)
|
||||
require.Equal(t, len(notificationsQuery.Result), 1)
|
||||
@@ -175,6 +179,7 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Two notifications with is_default", func(t *testing.T) {
|
||||
setup()
|
||||
dc := newNotificationProvisioner(sqlStore, &fakeAlertNotification{}, encryptionService, nil, logger)
|
||||
@@ -194,7 +199,7 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
Uid: "notifier0",
|
||||
Type: "slack",
|
||||
}
|
||||
err := sqlStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
|
||||
err := ns.SQLStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
|
||||
require.NoError(t, err)
|
||||
existingNotificationCmd = models.CreateAlertNotificationCommand{
|
||||
Name: "channel3",
|
||||
@@ -202,11 +207,11 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
Uid: "notifier3",
|
||||
Type: "slack",
|
||||
}
|
||||
err = sqlStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
|
||||
err = ns.SQLStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
notificationsQuery := models.GetAllAlertNotificationsQuery{OrgId: 1}
|
||||
err = sqlStore.GetAllAlertNotifications(context.Background(), ¬ificationsQuery)
|
||||
err = ns.GetAllAlertNotifications(context.Background(), ¬ificationsQuery)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, notificationsQuery.Result)
|
||||
require.Equal(t, len(notificationsQuery.Result), 2)
|
||||
@@ -223,6 +228,7 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
|
||||
t.Run("Can read correct properties with orgName instead of orgId", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
existingOrg1 := models.GetOrgByNameQuery{Name: "Main Org. 1"}
|
||||
err := sqlStore.GetOrgByNameHandler(context.Background(), &existingOrg1)
|
||||
require.NoError(t, err)
|
||||
@@ -238,7 +244,7 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
Uid: "notifier2",
|
||||
Type: "slack",
|
||||
}
|
||||
err = sqlStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
|
||||
err = ns.SQLStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
dc := newNotificationProvisioner(sqlStore, &fakeAlertNotification{}, encryptionService, nil, logger)
|
||||
@@ -270,7 +276,7 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
t.Fatalf("applyChanges return an error %v", err)
|
||||
}
|
||||
notificationsQuery := models.GetAllAlertNotificationsQuery{OrgId: 1}
|
||||
err = sqlStore.GetAllAlertNotifications(context.Background(), ¬ificationsQuery)
|
||||
err = ns.GetAllAlertNotifications(context.Background(), ¬ificationsQuery)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, notificationsQuery.Result)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user