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:
43
internal/envelope/envelope_test.go
Normal file
43
internal/envelope/envelope_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user