docs: better descibe `email_config.to` fromat (#3760)

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
This commit is contained in:
Christoph Maser 2024-03-14 13:56:31 +01:00 committed by GitHub
parent 54af8b59ab
commit f82574a376
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 5 deletions

View File

@ -15,6 +15,8 @@ package config
import ( import (
"errors" "errors"
"net/mail"
"reflect"
"strings" "strings"
"testing" "testing"
@ -60,6 +62,47 @@ headers:
} }
} }
func TestEmailToAllowsMultipleAdresses(t *testing.T) {
in := `
to: 'a@example.com, ,b@example.com,c@example.com'
`
var cfg EmailConfig
err := yaml.UnmarshalStrict([]byte(in), &cfg)
if err != nil {
t.Fatal(err)
}
expected := []*mail.Address{
{Address: "a@example.com"},
{Address: "b@example.com"},
{Address: "c@example.com"},
}
res, err := mail.ParseAddressList(cfg.To)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(res, expected) {
t.Fatalf("expected %v, got %v", expected, res)
}
}
func TestEmailDisallowMalformed(t *testing.T) {
in := `
to: 'a@'
`
var cfg EmailConfig
err := yaml.UnmarshalStrict([]byte(in), &cfg)
if err != nil {
t.Fatal(err)
}
_, err = mail.ParseAddressList(cfg.To)
if err == nil {
t.Fatalf("no error returned, expected:\n%v", "mail: no angle-addr")
}
}
func TestPagerdutyTestRoutingKey(t *testing.T) { func TestPagerdutyTestRoutingKey(t *testing.T) {
t.Run("error if no routing key or key file", func(t *testing.T) { t.Run("error if no routing key or key file", func(t *testing.T) {
in := ` in := `

View File

@ -867,6 +867,7 @@ webhook_url_file: <filepath>
[ send_resolved: <boolean> | default = false ] [ send_resolved: <boolean> | default = false ]
# The email address to send notifications to. # The email address to send notifications to.
# Allows a comma separated list of rfc5322 compliant email addresses.
to: <tmpl_string> to: <tmpl_string>
# The sender's address. # The sender's address.