mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Add method to reset notification policy tree back to the default (#51934)
* Define route and run codegen * Wire up HTTP layer * Update API layer and test fakes * Implement reset of policy tree * Implement service layer test and authorization bindings * API layer testing * Be more specific when injecting settings
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/prometheus/alertmanager/config"
|
||||
"github.com/prometheus/alertmanager/timeinterval"
|
||||
"github.com/prometheus/common/model"
|
||||
@@ -213,6 +214,17 @@ func TestNotificationPolicyService(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, ErrValidation)
|
||||
})
|
||||
|
||||
t.Run("deleting route replaces with default", func(t *testing.T) {
|
||||
sut := createNotificationPolicyServiceSut()
|
||||
|
||||
tree, err := sut.ResetPolicyTree(context.Background(), 1)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "grafana-default-email", tree.Receiver)
|
||||
require.Nil(t, tree.Routes)
|
||||
require.Nil(t, tree.GroupBy)
|
||||
})
|
||||
}
|
||||
|
||||
func createNotificationPolicyServiceSut() *NotificationPolicyService {
|
||||
@@ -221,6 +233,9 @@ func createNotificationPolicyServiceSut() *NotificationPolicyService {
|
||||
provenanceStore: NewFakeProvisioningStore(),
|
||||
xact: newNopTransactionManager(),
|
||||
log: log.NewNopLogger(),
|
||||
settings: setting.UnifiedAlertingSettings{
|
||||
DefaultConfiguration: setting.GetAlertmanagerDefaultConfiguration(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user