@@ -9,6 +9,8 @@ import (
99
1010type ValidatorTest struct {
1111 auth_email_file *os.File
12+ done chan bool
13+ update_seen bool
1214}
1315
1416func NewValidatorTest(t *testing.T) *ValidatorTest {
@@ -18,13 +20,26 @@ func NewValidatorTest(t *testing.T) *ValidatorTest {
1820 if err != nil {
1921 t.Fatal("failed to create temp file: " + err.Error())
2022 }
23+ vt.done = make(chan bool)
2124 return vt
2225}
2326
2427func (vt *ValidatorTest) TearDown() {
28+ vt.done <- true
2529 os.Remove(vt.auth_email_file.Name())
2630}
2731
32+func (vt *ValidatorTest) NewValidator(domains []string,
33+ updated chan<- bool) func(string) bool {
34+ return newValidatorImpl(domains, vt.auth_email_file.Name(),
35+ vt.done, func() {
36+ if vt.update_seen == false {
37+ updated <- true
38+ vt.update_seen = true
39+ }
40+ })
41+}
42+
2843// This will close vt.auth_email_file.
2944func (vt *ValidatorTest) WriteEmails(t *testing.T, emails []string) {
3045 defer vt.auth_email_file.Close()
@@ -41,7 +56,7 @@ func TestValidatorEmpty(t *testing.T) {
4156
4257 vt.WriteEmails(t, []string(nil))
4358 domains := []string(nil)
44− validator := NewValidator(domains, vt.auth_email_file.Name())
59+ validator := vt.NewValidator(domains, nil)
4560
4661 if validator("foo.bar@example.com") {
4762 t.Error("nothing should validate when the email and " +
@@ -55,7 +70,7 @@ func TestValidatorSingleEmail(t *testing.T) {
5570
5671 vt.WriteEmails(t, []string{"foo.bar@example.com"})
5772 domains := []string(nil)
58− validator := NewValidator(domains, vt.auth_email_file.Name())
73+ validator := vt.NewValidator(domains, nil)
5974
6075 if !validator("foo.bar@example.com") {
6176 t.Error("email should validate")
@@ -72,7 +87,7 @@ func TestValidatorSingleDomain(t *testing.T) {
7287
7388 vt.WriteEmails(t, []string(nil))
7489 domains := []string{"example.com"}
75− validator := NewValidator(domains, vt.auth_email_file.Name())
90+ validator := vt.NewValidator(domains, nil)
7691
7792 if !validator("foo.bar@example.com") {
7893 t.Error("email should validate")
@@ -91,7 +106,7 @@ func TestValidatorMultipleEmailsMultipleDomains(t *testing.T) {
91106 "plugh@example.com",
92107 })
93108 domains := []string{"example0.com", "example1.com"}
94− validator := NewValidator(domains, vt.auth_email_file.Name())
109+ validator := vt.NewValidator(domains, nil)
95110
96111 if !validator("foo.bar@example0.com") {
97112 t.Error("email from first domain should validate")
@@ -117,7 +132,7 @@ func TestValidatorComparisonsAreCaseInsensitive(t *testing.T) {
117132
118133 vt.WriteEmails(t, []string{"Foo.Bar@Example.Com"})
119134 domains := []string{"Frobozz.Com"}
120− validator := NewValidator(domains, vt.auth_email_file.Name())
135+ validator := vt.NewValidator(domains, nil)
121136
122137 if !validator("foo.bar@example.com") {
123138 t.Error("loaded email addresses are not lower-cased")