mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Email notification channel in ngalert Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in> * Use existing templating system Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in> * Update template and add unit tests Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package channels
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestEmailNotifier(t *testing.T) {
|
|
t.Run("empty settings should return error", func(t *testing.T) {
|
|
json := `{ }`
|
|
|
|
settingsJSON, _ := simplejson.NewJson([]byte(json))
|
|
model := &models.AlertNotification{
|
|
Name: "ops",
|
|
Type: "email",
|
|
Settings: settingsJSON,
|
|
}
|
|
|
|
_, err := NewEmailNotifier(model)
|
|
require.Error(t, err)
|
|
})
|
|
|
|
t.Run("from settings", func(t *testing.T) {
|
|
json := `{"addresses": "ops@grafana.org"}`
|
|
settingsJSON, err := simplejson.NewJson([]byte(json))
|
|
require.NoError(t, err)
|
|
|
|
emailNotifier, err := NewEmailNotifier(&models.AlertNotification{
|
|
Name: "ops",
|
|
Type: "email",
|
|
Settings: settingsJSON,
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
require.Equal(t, "ops", emailNotifier.Name)
|
|
require.Equal(t, "email", emailNotifier.Type)
|
|
require.Equal(t, []string{"ops@grafana.org"}, emailNotifier.Addresses)
|
|
})
|
|
|
|
t.Run("from settings with two emails", func(t *testing.T) {
|
|
json := `{"addresses": "ops@grafana.org;dev@grafana.org"}`
|
|
settingsJSON, err := simplejson.NewJson([]byte(json))
|
|
require.NoError(t, err)
|
|
|
|
emailNotifier, err := NewEmailNotifier(&models.AlertNotification{
|
|
Name: "ops",
|
|
Type: "email",
|
|
Settings: settingsJSON,
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
require.Equal(t, "ops", emailNotifier.Name)
|
|
require.Equal(t, "email", emailNotifier.Type)
|
|
require.Equal(t, []string{"ops@grafana.org", "dev@grafana.org"}, emailNotifier.Addresses)
|
|
})
|
|
}
|