Alerting: Remove fake secret service in tests (#60488)

This commit is contained in:
Yuri Tseretyan 2022-12-16 15:01:41 -05:00 committed by GitHub
parent 9ad45aedcf
commit 92d12fdefa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 73 additions and 101 deletions

View File

@ -7,9 +7,6 @@ import (
"net/url"
"testing"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
@ -54,8 +51,9 @@ func TestNewAlertmanagerNotifier(t *testing.T) {
SecureSettings: secureSettings,
}
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
decryptFn := secretsService.GetDecryptedValue
decryptFn := func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
}
cfg, err := NewAlertmanagerConfig(m, decryptFn)
if c.expectedInitError != "" {
require.Equal(t, c.expectedInitError, err.Error())
@ -151,8 +149,9 @@ func TestAlertmanagerNotifier_Notify(t *testing.T) {
SecureSettings: secureSettings,
}
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
decryptFn := secretsService.GetDecryptedValue
decryptFn := func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
}
cfg, err := NewAlertmanagerConfig(m, decryptFn)
require.NoError(t, err)
sn := NewAlertmanagerNotifier(cfg, &FakeLogger{}, images, tmpl, decryptFn)

View File

@ -10,9 +10,6 @@ import (
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
)
func TestLineNotifier(t *testing.T) {
@ -99,8 +96,6 @@ func TestLineNotifier(t *testing.T) {
settingsJSON := json.RawMessage(c.settings)
secureSettings := make(map[string][]byte)
webhookSender := mockNotificationService()
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
decryptFn := secretsService.GetDecryptedValue
fc := FactoryConfig{
Config: &NotificationChannelConfig{
@ -111,7 +106,9 @@ func TestLineNotifier(t *testing.T) {
},
// TODO: allow changing the associated values for different tests.
NotificationService: webhookSender,
DecryptFunc: decryptFn,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
Template: tmpl,
Logger: &FakeLogger{},
}

View File

@ -7,9 +7,6 @@ import (
"testing"
"time"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
@ -235,8 +232,6 @@ func TestOpsgenieNotifier(t *testing.T) {
webhookSender := mockNotificationService()
webhookSender.Webhook.Body = "<not-sent>"
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
decryptFn := secretsService.GetDecryptedValue
fc := FactoryConfig{
Config: &NotificationChannelConfig{
@ -246,7 +241,9 @@ func TestOpsgenieNotifier(t *testing.T) {
SecureSettings: secureSettings,
},
NotificationService: webhookSender,
DecryptFunc: decryptFn,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
ImageStore: &UnavailableImageStore{},
Template: tmpl,
Logger: &FakeLogger{},

View File

@ -14,9 +14,6 @@ import (
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
)
func TestPagerdutyNotifier(t *testing.T) {
@ -278,9 +275,6 @@ func TestPagerdutyNotifier(t *testing.T) {
settingsJSON := json.RawMessage(c.settings)
secureSettings := make(map[string][]byte)
webhookSender := mockNotificationService()
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
decryptFn := secretsService.GetDecryptedValue
fc := FactoryConfig{
Config: &NotificationChannelConfig{
Name: "pageduty_testing",
@ -289,7 +283,9 @@ func TestPagerdutyNotifier(t *testing.T) {
SecureSettings: secureSettings,
},
NotificationService: webhookSender,
DecryptFunc: decryptFn,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
Template: tmpl,
Logger: &FakeLogger{},
}

View File

@ -12,9 +12,6 @@ import (
"strings"
"testing"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
@ -214,8 +211,6 @@ func TestPushoverNotifier(t *testing.T) {
secureSettings := make(map[string][]byte)
webhookSender := mockNotificationService()
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
decryptFn := secretsService.GetDecryptedValue
fc := FactoryConfig{
Config: &NotificationChannelConfig{
@ -226,7 +221,9 @@ func TestPushoverNotifier(t *testing.T) {
},
ImageStore: images,
NotificationService: webhookSender,
DecryptFunc: decryptFn,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
Template: tmpl,
Logger: &FakeLogger{},
}

View File

@ -7,9 +7,6 @@ import (
"testing"
"time"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
@ -147,15 +144,15 @@ func TestSensuGoNotifier(t *testing.T) {
}
webhookSender := mockNotificationService()
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
decryptFn := secretsService.GetDecryptedValue
fc := FactoryConfig{
Config: m,
ImageStore: images,
NotificationService: webhookSender,
Template: tmpl,
DecryptFunc: decryptFn,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
Logger: &FakeLogger{},
}

View File

@ -19,8 +19,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/grafana/grafana/pkg/setting"
)
@ -421,7 +419,6 @@ func setupSlackForTests(t *testing.T, settings string) (*SlackNotifier, *slackRe
URL: "https://www.example.com/test.png",
}},
}
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
notificationService := mockNotificationService()
c := FactoryConfig{
@ -433,7 +430,9 @@ func setupSlackForTests(t *testing.T, settings string) (*SlackNotifier, *slackRe
},
ImageStore: images,
NotificationService: notificationService,
DecryptFunc: secretsService.GetDecryptedValue,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
Template: tmpl,
Logger: &FakeLogger{},
}

View File

@ -7,9 +7,6 @@ import (
"strings"
"testing"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
@ -120,8 +117,6 @@ func TestTelegramNotifier(t *testing.T) {
require.NoError(t, err)
secureSettings := make(map[string][]byte)
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
decryptFn := secretsService.GetDecryptedValue
notificationService := mockNotificationService()
fc := FactoryConfig{
@ -133,7 +128,9 @@ func TestTelegramNotifier(t *testing.T) {
},
ImageStore: images,
NotificationService: notificationService,
DecryptFunc: decryptFn,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
Template: tmpl,
Logger: &FakeLogger{},
}

View File

@ -6,9 +6,6 @@ import (
"net/url"
"testing"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
@ -121,7 +118,6 @@ func TestThreemaNotifier(t *testing.T) {
settingsJSON := json.RawMessage(c.settings)
secureSettings := make(map[string][]byte)
webhookSender := mockNotificationService()
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
fc := FactoryConfig{
Config: &NotificationChannelConfig{
@ -133,7 +129,9 @@ func TestThreemaNotifier(t *testing.T) {
NotificationService: webhookSender,
ImageStore: images,
Template: tmpl,
DecryptFunc: secretsService.GetDecryptedValue,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
Logger: &FakeLogger{},
}

View File

@ -8,9 +8,6 @@ import (
"strings"
"testing"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
@ -108,8 +105,6 @@ func TestWebexNotifier(t *testing.T) {
settingsJSON := json.RawMessage(c.settings)
secureSettings := make(map[string][]byte)
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
decryptFn := secretsService.GetDecryptedValue
notificationService := mockNotificationService()
fc := FactoryConfig{
@ -121,7 +116,9 @@ func TestWebexNotifier(t *testing.T) {
},
ImageStore: images,
NotificationService: notificationService,
DecryptFunc: decryptFn,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
Template: tmpl,
Logger: &FakeLogger{},
}

View File

@ -7,9 +7,6 @@ import (
"net/url"
"testing"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/template"
"github.com/prometheus/alertmanager/types"
@ -348,12 +345,13 @@ func TestWebhookNotifier(t *testing.T) {
}
webhookSender := mockNotificationService()
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
fc := FactoryConfig{
Config: m,
NotificationService: webhookSender,
DecryptFunc: secretsService.GetDecryptedValue,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
ImageStore: &UnavailableImageStore{},
Template: tmpl,
Logger: &FakeLogger{},

View File

@ -11,9 +11,6 @@ import (
"testing"
"time"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
@ -166,12 +163,13 @@ func TestWeComNotifier(t *testing.T) {
}
webhookSender := mockNotificationService()
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
fc := FactoryConfig{
Config: m,
NotificationService: webhookSender,
DecryptFunc: secretsService.GetDecryptedValue,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
ImageStore: nil,
Template: tmpl,
Logger: &FakeLogger{},
@ -349,12 +347,13 @@ func TestWeComNotifierAPIAPP(t *testing.T) {
}
webhookSender := mockNotificationService()
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
fc := FactoryConfig{
Config: m,
NotificationService: webhookSender,
DecryptFunc: secretsService.GetDecryptedValue,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
ImageStore: nil,
Template: tmpl,
Logger: &FakeLogger{},
@ -533,12 +532,13 @@ func TestWeComFactory(t *testing.T) {
}
webhookSender := mockNotificationService()
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
fc := FactoryConfig{
Config: m,
NotificationService: webhookSender,
DecryptFunc: secretsService.GetDecryptedValue,
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
return fallback
},
ImageStore: nil,
Logger: &FakeLogger{},
}