mirror of
https://github.com/mjl-/mox.git
synced 2024-12-27 17:03:47 +03:00
30 lines
1 KiB
Go
30 lines
1 KiB
Go
|
package message
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestMessageIDCanonical(t *testing.T) {
|
||
|
check := func(s string, expID string, expRaw bool, expErr error) {
|
||
|
t.Helper()
|
||
|
|
||
|
id, raw, err := MessageIDCanonical(s)
|
||
|
if id != expID || raw != expRaw || (expErr == nil) != (err == nil) || err != nil && !errors.Is(err, expErr) {
|
||
|
t.Fatalf("got message-id %q, raw %v, err %v, expected %q %v %v, for message-id %q", id, raw, err, expID, expRaw, expErr, s)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
check("bogus", "", false, errBadMessageID)
|
||
|
check("<bogus@host", "", false, errBadMessageID)
|
||
|
check("bogus@host>", "", false, errBadMessageID)
|
||
|
check("<>", "", false, errBadMessageID)
|
||
|
check("<user@domain>", "user@domain", false, nil)
|
||
|
check("<USER@DOMAIN>", "user@domain", false, nil)
|
||
|
check("<user@[10.0.0.1]>", "user@[10.0.0.1]", true, nil)
|
||
|
check("<user@domain> (added by postmaster@isp.example)", "user@domain", false, nil)
|
||
|
check("<user@domain> other", "user@domain", false, nil)
|
||
|
check("<User@Domain@Time>", "user@domain@time", true, nil)
|
||
|
check("<User>", "user", true, nil)
|
||
|
}
|