Skip to content

The only tool you need to know what is happening and how to fix it.

846 B
Raw Blame
package notifications

import "testing"

func TestEmailAdapterValidate(t *testing.T) {
	eleven := make([]string, 11)
	for i := range eleven {
		eleven[i] = "[email protected]"
	}
	cases := []struct {
		name       string
		recipients []string
		ok         bool
	}{
		{"bare address", []string{"[email protected]"}, true},
		{"display name", []string{"Ops Team <[email protected]>"}, true},
		{"comma-joined pair", []string{"[email protected], [email protected]"}, false},
		{"header injection", []string{"[email protected]\r\nBcc: [email protected]"}, false},
		{"missing at", []string{"ops.example.com"}, false},
		{"empty", nil, false},
		{"eleven recipients", eleven, false},
	}
	for _, c := range cases {
		err := (&EmailAdapter{Recipients: c.recipients}).Validate()
		if (err == nil) != c.ok {
			t.Errorf("%s: err = %v, want ok=%v", c.name, err, c.ok)
		}
	}
}