1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-19 14:57:04 +00:00

Introduce an "envelope" package

This patch introduces an "envelope" package which, for now, provides simple
utilities for getting the user and domain of an address.

It also changes the couriers to use it (but other implementations remain, will
be moved over in subsequent patches).
This commit is contained in:
Alberto Bertogli
2016-07-19 23:18:40 +01:00
parent 831ef13132
commit 362ef6f6d0
6 changed files with 97 additions and 28 deletions

View File

@@ -0,0 +1,43 @@
package envelope
import (
"testing"
"blitiri.com.ar/go/chasquid/internal/set"
)
func TestSplit(t *testing.T) {
cases := []struct {
addr, user, domain string
}{
{"lalala@lelele", "lalala", "lelele"},
}
for _, c := range cases {
if user := UserOf(c.addr); user != c.user {
t.Errorf("%q: expected user %q, got %q", c.addr, c.user, user)
}
if domain := DomainOf(c.addr); domain != c.domain {
t.Errorf("%q: expected domain %q, got %q",
c.addr, c.domain, domain)
}
}
}
func TestDomainIn(t *testing.T) {
ls := set.NewString("domain1", "domain2")
cases := []struct {
addr string
in bool
}{
{"u@domain1", true},
{"u@domain2", true},
{"u@domain3", false},
{"u", true},
}
for _, c := range cases {
if in := DomainIn(c.addr, ls); in != c.in {
t.Errorf("%q: expected %v, got %v", c.addr, c.in, in)
}
}
}