diff --git a/api/api_test.go b/api/api_test.go index 2494131a5..8327a2879 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -40,8 +40,8 @@ func TestRequestFailure(t *testing.T) { resp, err := Request(req) assert.Equal(t, (*simplejson.Json)(nil), resp) assert.NotEqual(t, nil, err) - if !strings.HasSuffix(err.Error(), "connection refused") { - t.Error("expected error when a connection fails") + if !strings.Contains(err.Error(), "refused") { + t.Error("expected error when a connection fails: ", err) } } diff --git a/validator.go b/validator.go index 5ed3615eb..5c58fb9c5 100644 --- a/validator.go +++ b/validator.go @@ -44,6 +44,7 @@ func (um *UserMap) LoadAuthenticatedEmailsFile() { if err != nil { log.Fatalf("failed opening authenticated-emails-file=%q, %s", um.usersFile, err) } + defer r.Close() csv_reader := csv.NewReader(r) csv_reader.Comma = ',' csv_reader.Comment = '#' diff --git a/validator_watcher_copy_test.go b/validator_watcher_copy_test.go new file mode 100644 index 000000000..35bed3a8c --- /dev/null +++ b/validator_watcher_copy_test.go @@ -0,0 +1,50 @@ +// +build go1.3 +// +build !plan9,!solaris,!windows + +// Turns out you can't copy over an existing file on Windows. + +package main + +import ( + "io/ioutil" + "os" + "testing" +) + +func (vt *ValidatorTest) UpdateEmailFileViaCopyingOver( + t *testing.T, emails []string) { + orig_file := vt.auth_email_file + var err error + vt.auth_email_file, err = ioutil.TempFile("", "test_auth_emails_") + if err != nil { + t.Fatal("failed to create temp file for copy: " + err.Error()) + } + vt.WriteEmails(t, emails) + err = os.Rename(vt.auth_email_file.Name(), orig_file.Name()) + if err != nil { + t.Fatal("failed to copy over temp file: " + err.Error()) + } + vt.auth_email_file = orig_file +} + +func TestValidatorOverwriteEmailListViaCopyingOver(t *testing.T) { + vt := NewValidatorTest(t) + defer vt.TearDown() + + vt.WriteEmails(t, []string{"xyzzy@example.com"}) + domains := []string(nil) + updated := make(chan bool) + validator := newValidatorImpl(domains, vt.auth_email_file.Name(), + func() { updated <- true }) + + if !validator("xyzzy@example.com") { + t.Error("email in list should validate") + } + + vt.UpdateEmailFileViaCopyingOver(t, []string{"plugh@example.com"}) + <-updated + + if validator("xyzzy@example.com") { + t.Error("email removed from list should not validate") + } +} diff --git a/validator_watcher_test.go b/validator_watcher_test.go index f02651d23..691644f82 100644 --- a/validator_watcher_test.go +++ b/validator_watcher_test.go @@ -19,22 +19,6 @@ func (vt *ValidatorTest) UpdateEmailFile(t *testing.T, emails []string) { vt.WriteEmails(t, emails) } -func (vt *ValidatorTest) UpdateEmailFileViaCopyingOver( - t *testing.T, emails []string) { - orig_file := vt.auth_email_file - var err error - vt.auth_email_file, err = ioutil.TempFile("", "test_auth_emails_") - if err != nil { - t.Fatal("failed to create temp file for copy: " + err.Error()) - } - vt.WriteEmails(t, emails) - err = os.Rename(vt.auth_email_file.Name(), orig_file.Name()) - if err != nil { - t.Fatal("failed to copy over temp file: " + err.Error()) - } - vt.auth_email_file = orig_file -} - func (vt *ValidatorTest) UpdateEmailFileViaRenameAndReplace( t *testing.T, emails []string) { orig_file := vt.auth_email_file @@ -98,28 +82,6 @@ func TestValidatorOverwriteEmailListDirectly(t *testing.T) { } } -func TestValidatorOverwriteEmailListViaCopyingOver(t *testing.T) { - vt := NewValidatorTest(t) - defer vt.TearDown() - - vt.WriteEmails(t, []string{"xyzzy@example.com"}) - domains := []string(nil) - updated := make(chan bool) - validator := newValidatorImpl(domains, vt.auth_email_file.Name(), - func() { updated <- true }) - - if !validator("xyzzy@example.com") { - t.Error("email in list should validate") - } - - vt.UpdateEmailFileViaCopyingOver(t, []string{"plugh@example.com"}) - <-updated - - if validator("xyzzy@example.com") { - t.Error("email removed from list should not validate") - } -} - func TestValidatorOverwriteEmailListViaRenameAndReplace(t *testing.T) { vt := NewValidatorTest(t) defer vt.TearDown()