Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Commit

Permalink
Fix tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mbland committed May 10, 2015
1 parent 6d95548 commit 75755d5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 40 deletions.
4 changes: 2 additions & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
1 change: 1 addition & 0 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '#'
Expand Down
50 changes: 50 additions & 0 deletions validator_watcher_copy_test.go
Original file line number Diff line number Diff line change
@@ -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{"[email protected]"})
domains := []string(nil)
updated := make(chan bool)
validator := newValidatorImpl(domains, vt.auth_email_file.Name(),
func() { updated <- true })

if !validator("[email protected]") {
t.Error("email in list should validate")
}

vt.UpdateEmailFileViaCopyingOver(t, []string{"[email protected]"})
<-updated

if validator("[email protected]") {
t.Error("email removed from list should not validate")
}
}
38 changes: 0 additions & 38 deletions validator_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,28 +82,6 @@ func TestValidatorOverwriteEmailListDirectly(t *testing.T) {
}
}

func TestValidatorOverwriteEmailListViaCopyingOver(t *testing.T) {
vt := NewValidatorTest(t)
defer vt.TearDown()

vt.WriteEmails(t, []string{"[email protected]"})
domains := []string(nil)
updated := make(chan bool)
validator := newValidatorImpl(domains, vt.auth_email_file.Name(),
func() { updated <- true })

if !validator("[email protected]") {
t.Error("email in list should validate")
}

vt.UpdateEmailFileViaCopyingOver(t, []string{"[email protected]"})
<-updated

if validator("[email protected]") {
t.Error("email removed from list should not validate")
}
}

func TestValidatorOverwriteEmailListViaRenameAndReplace(t *testing.T) {
vt := NewValidatorTest(t)
defer vt.TearDown()
Expand Down

0 comments on commit 75755d5

Please sign in to comment.