10type ValidatorTest struct {
11 authEmailFile *os.File
16func NewValidatorTest(t *testing.T) *ValidatorTest {
17 vt := &ValidatorTest{}
19 vt.authEmailFile, err = ioutil.TempFile("", "test_auth_emails_")
21 t.Fatal("failed to create temp file: " + err.Error())
23 vt.done = make(chan bool, 1)
27func (vt *ValidatorTest) TearDown() {
29 os.Remove(vt.authEmailFile.Name())
32func (vt *ValidatorTest) NewValidator(domains []string,
33 updated chan<- bool) func(string) bool {
34 return newValidatorImpl(domains, vt.authEmailFile.Name(),
36 if vt.updateSeen == false {
43// This will close vt.authEmailFile.
44func (vt *ValidatorTest) WriteEmails(t *testing.T, emails []string) {
45 defer vt.authEmailFile.Close()
46 vt.authEmailFile.WriteString(strings.Join(emails, "\n"))
47 if err := vt.authEmailFile.Close(); err != nil {
48 t.Fatal("failed to close temp file " +
49 vt.authEmailFile.Name() + ": " + err.Error())
53func TestValidatorEmpty(t *testing.T) {
54 vt := NewValidatorTest(t)
57 vt.WriteEmails(t, []string(nil))
58 domains := []string(nil)
59 validator := vt.NewValidator(domains, nil)
61 if validator("foo.bar@example.com") {
62 t.Error("nothing should validate when the email and " +
63 "domain lists are empty")
67func TestValidatorSingleEmail(t *testing.T) {
68 vt := NewValidatorTest(t)
71 vt.WriteEmails(t, []string{"foo.bar@example.com"})
72 domains := []string(nil)
73 validator := vt.NewValidator(domains, nil)
75 if !validator("foo.bar@example.com") {
76 t.Error("email should validate")
78 if validator("baz.quux@example.com") {
79 t.Error("email from same domain but not in list " +
80 "should not validate when domain list is empty")
84func TestValidatorSingleDomain(t *testing.T) {
85 vt := NewValidatorTest(t)
88 vt.WriteEmails(t, []string(nil))
89 domains := []string{"example.com"}
90 validator := vt.NewValidator(domains, nil)
92 if !validator("foo.bar@example.com") {
93 t.Error("email should validate")
95 if !validator("baz.quux@example.com") {
96 t.Error("email from same domain should validate")
100func TestValidatorMultipleEmailsMultipleDomains(t *testing.T) {
101 vt := NewValidatorTest(t)
104 vt.WriteEmails(t, []string{
108 domains := []string{"example0.com", "example1.com"}
109 validator := vt.NewValidator(domains, nil)
111 if !validator("foo.bar@example0.com") {
112 t.Error("email from first domain should validate")
114 if !validator("baz.quux@example1.com") {
115 t.Error("email from second domain should validate")
117 if !validator("xyzzy@example.com") {
118 t.Error("first email in list should validate")
120 if !validator("plugh@example.com") {
121 t.Error("second email in list should validate")
123 if validator("xyzzy.plugh@example.com") {
124 t.Error("email not in list that matches no domains " +
125 "should not validate")
129func TestValidatorComparisonsAreCaseInsensitive(t *testing.T) {
130 vt := NewValidatorTest(t)
133 vt.WriteEmails(t, []string{"Foo.Bar@Example.Com"})
134 domains := []string{"Frobozz.Com"}
135 validator := vt.NewValidator(domains, nil)
137 if !validator("foo.bar@example.com") {
138 t.Error("loaded email addresses are not lower-cased")
140 if !validator("Foo.Bar@Example.Com") {
141 t.Error("validated email addresses are not lower-cased")
143 if !validator("foo.bar@frobozz.com") {
144 t.Error("loaded domains are not lower-cased")
146 if !validator("foo.bar@Frobozz.Com") {
147 t.Error("validated domains are not lower-cased")
151func TestValidatorIgnoreSpacesInAuthEmails(t *testing.T) {
152 vt := NewValidatorTest(t)
155 vt.WriteEmails(t, []string{" foo.bar@example.com "})
156 domains := []string(nil)
157 validator := vt.NewValidator(domains, nil)
159 if !validator("foo.bar@example.com") {
160 t.Error("email should validate")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list