docs: better descibe `email_config.to` fromat (#3760)
Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
This commit is contained in:
parent
54af8b59ab
commit
f82574a376
|
@ -15,6 +15,8 @@ package config
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"net/mail"
|
||||
"reflect"
|
||||
"strings"
|
||||
"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) {
|
||||
t.Run("error if no routing key or key file", func(t *testing.T) {
|
||||
in := `
|
||||
|
|
|
@ -867,6 +867,7 @@ webhook_url_file: <filepath>
|
|||
[ send_resolved: <boolean> | default = false ]
|
||||
|
||||
# The email address to send notifications to.
|
||||
# Allows a comma separated list of rfc5322 compliant email addresses.
|
||||
to: <tmpl_string>
|
||||
|
||||
# The sender's address.
|
||||
|
|
Loading…
Reference in New Issue