2021-03-24 09:20:44 -05:00
|
|
|
package notifier
|
|
|
|
|
|
|
|
import (
|
2021-04-23 09:19:03 -05:00
|
|
|
"context"
|
2021-03-24 09:20:44 -05:00
|
|
|
"testing"
|
2021-04-22 10:12:18 -05:00
|
|
|
"time"
|
2021-03-24 09:20:44 -05:00
|
|
|
|
2022-05-24 08:24:55 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
2021-11-04 11:47:21 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/secrets/database"
|
|
|
|
|
2022-01-07 02:40:09 -06:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2022-10-19 08:02:15 -05:00
|
|
|
"github.com/grafana/grafana/pkg/infra/db"
|
2021-10-07 09:33:50 -05:00
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
2021-04-30 11:28:06 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
2021-05-13 13:01:38 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
2021-11-04 11:47:21 -05:00
|
|
|
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
|
2021-04-13 07:02:44 -05:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2021-03-24 09:20:44 -05:00
|
|
|
)
|
|
|
|
|
2021-05-13 13:01:38 -05:00
|
|
|
func setupAMTest(t *testing.T) *Alertmanager {
|
2022-03-22 09:43:29 -05:00
|
|
|
dir := t.TempDir()
|
2021-05-13 13:01:38 -05:00
|
|
|
cfg := &setting.Cfg{
|
2021-05-13 05:38:12 -05:00
|
|
|
DataPath: dir,
|
|
|
|
}
|
2021-05-13 13:01:38 -05:00
|
|
|
|
2021-09-14 06:55:01 -05:00
|
|
|
m := metrics.NewAlertmanagerMetrics(prometheus.NewRegistry())
|
2022-10-19 08:02:15 -05:00
|
|
|
sqlStore := db.InitTestDB(t)
|
2021-09-14 06:55:01 -05:00
|
|
|
s := &store.DBstore{
|
2022-07-15 13:13:30 -05:00
|
|
|
Cfg: setting.UnifiedAlertingSettings{
|
|
|
|
BaseInterval: 10 * time.Second,
|
2022-11-22 01:09:15 -06:00
|
|
|
DefaultRuleEvaluationInterval: time.Minute,
|
2022-07-15 13:13:30 -05:00
|
|
|
},
|
2022-05-24 08:24:55 -05:00
|
|
|
SQLStore: sqlStore,
|
|
|
|
Logger: log.New("alertmanager-test"),
|
|
|
|
DashboardService: dashboards.NewFakeDashboardService(t),
|
2021-05-13 13:01:38 -05:00
|
|
|
}
|
|
|
|
|
2021-12-27 17:01:17 -06:00
|
|
|
kvStore := NewFakeKVStore(t)
|
2021-11-04 11:47:21 -05:00
|
|
|
secretsService := secretsManager.SetupTestService(t, database.ProvideSecretsStore(sqlStore))
|
|
|
|
decryptFn := secretsService.GetDecryptedValue
|
2022-01-26 09:42:40 -06:00
|
|
|
am, err := newAlertmanager(context.Background(), 1, cfg, s, kvStore, &NilPeer{}, decryptFn, nil, m)
|
2021-05-13 13:01:38 -05:00
|
|
|
require.NoError(t, err)
|
|
|
|
return am
|
|
|
|
}
|
|
|
|
|
2023-01-23 04:30:10 -06:00
|
|
|
func TestAlertmanager_newAlertmanager(t *testing.T) {
|
2021-05-13 13:01:38 -05:00
|
|
|
am := setupAMTest(t)
|
2023-01-23 04:30:10 -06:00
|
|
|
require.False(t, am.Ready())
|
2022-03-23 03:49:02 -05:00
|
|
|
}
|