TestSelfSend_DetectionEdgeCases: case-insensitive, whitespace- trimmed, single-address requirement. Mixed/external recipients must fall through to SMTP (covered indirectly — TestSendEmailViaSMTP already exercises the non-loopback path).
(t *testing.T)
| 19 | // fall through to SMTP (covered indirectly — TestSendEmailViaSMTP |
| 20 | // already exercises the non-loopback path). |
| 21 | func TestSelfSend_DetectionEdgeCases(t *testing.T) { |
| 22 | cases := []struct { |
| 23 | name string |
| 24 | to []string |
| 25 | cc []string |
| 26 | want bool |
| 27 | reason string |
| 28 | }{ |
| 29 | {"exact match", []string{"bot@x.com"}, nil, true, ""}, |
| 30 | {"case-insensitive local", []string{"BOT@x.com"}, nil, true, "ASCII case-insensitive"}, |
| 31 | {"case-insensitive domain", []string{"bot@X.COM"}, nil, true, "domain comparison is case-insensitive"}, |
| 32 | {"whitespace trimmed", []string{" bot@x.com "}, nil, true, "trim should normalize"}, |
| 33 | {"different address", []string{"other@x.com"}, nil, false, "not self"}, |
| 34 | {"self plus external in To", []string{"bot@x.com", "other@x.com"}, nil, false, "external recipient → SMTP"}, |
| 35 | {"self plus cc", []string{"bot@x.com"}, []string{"cc@x.com"}, false, "cc → SMTP"}, |
| 36 | {"empty to", []string{}, nil, false, ""}, |
| 37 | } |
| 38 | for _, c := range cases { |
| 39 | t.Run(c.name, func(t *testing.T) { |
| 40 | req := outbound.SendRequest{To: c.to, CC: c.cc} |
| 41 | got := agent.IsSelfSendForTest(req, "bot@x.com") |
| 42 | if got != c.want { |
| 43 | t.Errorf("isSelfSend(%v, cc=%v) = %v, want %v (%s)", c.to, c.cc, got, c.want, c.reason) |
| 44 | } |
| 45 | }) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // setupCoreAPI builds an *agent.API wired to a real test DB so tests can drive |
| 50 | // the extracted outbound core (DeliverOutbound) directly. The legacy |
nothing calls this directly
no test coverage detected