1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-21 19:47:03 +00:00

Commit incomplete ParseEmailAddress()

This commit is contained in:
James Hillyerd
2013-11-04 16:18:30 -08:00
parent 21ad7a2452
commit 193a5f6f13
2 changed files with 86 additions and 23 deletions

View File

@@ -53,9 +53,9 @@ func TestValidateDomain(t *testing.T) {
func TestValidateLocal(t *testing.T) {
var testTable = []struct {
input string
input string
expect bool
msg string
msg string
}{
{"", false, "Empty local is not valid"},
{"a", true, "Single letter should be fine"},
@@ -99,8 +99,36 @@ func TestValidateLocal(t *testing.T) {
}
for _, tt := range testTable {
if ValidateLocalPart(tt.input) != tt.expect {
_, _, err := ParseEmailAddress(tt.input + "@domain.com")
if (err != nil) == tt.expect {
if err != nil {
t.Logf("Got error: %s", err)
}
t.Errorf("Expected %v for %q: %s", tt.expect, tt.input, tt.msg)
}
}
}
func TestParseEmailAddress(t *testing.T) {
var testTable = []struct {
input, local, domain string
}{
{"root@localhost", "root", "localhost"},
}
for _, tt := range testTable {
local, domain, err := ParseEmailAddress(tt.input)
if err != nil {
t.Errorf("Error when parsing %q: %s", tt.input, err)
} else {
if tt.local != local {
t.Errorf("When parsing %q, expected local %q, got %q instead",
tt.input, tt.local, local)
}
if tt.domain != domain {
t.Errorf("When parsing %q, expected domain %q, got %q instead",
tt.input, tt.domain, domain)
}
}
}
}