1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00
Files
go-chasquid-smtp/internal/envelope/envelope_test.go
Alberto Bertogli 362ef6f6d0 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).
2016-07-22 01:44:45 +01:00

44 lines
852 B
Go

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)
}
}
}