Alerting: Migrate to integration schema (#111643)
* update tests to assert against snapshot * remove channel_config package replaced by schemas from alerting module * update references to use new schema
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/notifier/channels_config"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
@@ -54,10 +53,17 @@ func TestIntegrationAvailableChannels(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 200, resp.StatusCode)
|
||||
|
||||
expNotifiers := channels_config.GetAvailableNotifiers()
|
||||
expJson, err := json.Marshal(expNotifiers)
|
||||
expectedBytes, err := os.ReadFile(path.Join("test-data", "alert-notifiers-v1-snapshot.json"))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, string(expJson), string(b))
|
||||
|
||||
require.NoError(t, err)
|
||||
if !assert.JSONEq(t, string(expectedBytes), string(b)) {
|
||||
var prettyJSON bytes.Buffer
|
||||
err := json.Indent(&prettyJSON, b, "", " ")
|
||||
require.NoError(t, err)
|
||||
err = os.WriteFile(path.Join("test-data", "alert-notifiers-v1-snapshot.json"), prettyJSON.Bytes(), 0o644)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("should return versioned notifiers", func(t *testing.T) {
|
||||
|
||||
@@ -17,11 +17,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/alerting/receivers"
|
||||
alertingLine "github.com/grafana/alerting/receivers/line"
|
||||
alertingPushover "github.com/grafana/alerting/receivers/pushover"
|
||||
alertingSlack "github.com/grafana/alerting/receivers/slack"
|
||||
alertingTelegram "github.com/grafana/alerting/receivers/telegram"
|
||||
alertingThreema "github.com/grafana/alerting/receivers/threema"
|
||||
alertingLine "github.com/grafana/alerting/receivers/line/v1"
|
||||
alertingPushover "github.com/grafana/alerting/receivers/pushover/v1"
|
||||
alertingSlack "github.com/grafana/alerting/receivers/slack/v1"
|
||||
alertingTelegram "github.com/grafana/alerting/receivers/telegram/v1"
|
||||
alertingThreema "github.com/grafana/alerting/receivers/threema/v1"
|
||||
alertingTemplates "github.com/grafana/alerting/templates"
|
||||
"github.com/prometheus/alertmanager/template"
|
||||
"github.com/prometheus/common/model"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@
|
||||
"description": "Send notifications to LINE notify",
|
||||
"versions": [
|
||||
{
|
||||
"typeAlias": "line",
|
||||
"version": "v1",
|
||||
"canCreate": true,
|
||||
"options": [
|
||||
@@ -8143,7 +8144,7 @@
|
||||
"type": "sns",
|
||||
"currentVersion": "v1",
|
||||
"name": "AWS SNS",
|
||||
"heading": "Webex settings",
|
||||
"heading": "AWS SNS settings",
|
||||
"description": "Sends notifications to AWS Simple Notification Service",
|
||||
"versions": [
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/alerting/receivers/schema"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -37,7 +38,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/notifier/channels_config"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/tests/api/alerting"
|
||||
@@ -1311,12 +1311,14 @@ func TestIntegrationCRUD(t *testing.T) {
|
||||
require.Equal(t, receiver, get)
|
||||
t.Run("should return secrets in secureFields but not settings", func(t *testing.T) {
|
||||
for _, integration := range get.Spec.Integrations {
|
||||
integrationType := schema.IntegrationType(integration.Type)
|
||||
t.Run(integration.Type, func(t *testing.T) {
|
||||
expected := notify.AllKnownConfigsForTesting[strings.ToLower(integration.Type)]
|
||||
var fields map[string]any
|
||||
require.NoError(t, json.Unmarshal([]byte(expected.Config), &fields))
|
||||
secretFields, err := channels_config.GetSecretKeysForContactPointType(integration.Type, channels_config.V1)
|
||||
require.NoError(t, err)
|
||||
typeSchema, ok := notify.GetSchemaVersionForIntegration(integrationType, schema.V1)
|
||||
require.True(t, ok)
|
||||
secretFields := typeSchema.GetSecretFieldsPaths()
|
||||
for _, field := range secretFields {
|
||||
if _, ok := fields[field]; !ok { // skip field that is not in the original setting
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user