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-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"
|
2023-01-30 02:55:35 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
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"
|
2023-10-12 07:43:10 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/tests/fakes"
|
2023-01-30 02:55:35 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/secrets/database"
|
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"
|
2024-02-09 08:35:39 -06:00
|
|
|
"github.com/grafana/grafana/pkg/tests/testsuite"
|
2021-03-24 09:20:44 -05:00
|
|
|
)
|
|
|
|
|
2024-02-09 08:35:39 -06:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
testsuite.Run(m)
|
|
|
|
}
|
|
|
|
|
2023-09-06 05:59:29 -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,
|
2023-04-28 09:56:59 -05:00
|
|
|
AppURL: "http://localhost:9093",
|
2021-05-13 05:38:12 -05:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2023-10-12 07:43:10 -05:00
|
|
|
kvStore := fakes.NewFakeKVStore(t)
|
2021-11-04 11:47:21 -05:00
|
|
|
secretsService := secretsManager.SetupTestService(t, database.ProvideSecretsStore(sqlStore))
|
|
|
|
decryptFn := secretsService.GetDecryptedValue
|
2024-03-22 17:37:33 -05:00
|
|
|
|
|
|
|
orgID := 1
|
|
|
|
stateStore := NewFileStore(int64(orgID), kvStore)
|
|
|
|
|
|
|
|
am, err := NewAlertmanager(context.Background(), 1, cfg, s, stateStore, &NilPeer{}, decryptFn, nil, m, false)
|
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
|
|
|
}
|