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:
Alexander Weaver
2022-07-08 16:23:18 -05:00
committed by GitHub
parent 05cdef5004
commit fce283d73e
12 changed files with 195 additions and 3 deletions

View File

@@ -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(),
},
}
}