MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / FakeSMTPServer

Function FakeSMTPServer

internal/testutil/fakesmtp.go:29–63  ·  view source on GitHub ↗

FakeSMTPServer starts a minimal SMTP server that accepts messages. Returns the address and a function to call to stop the server and get received messages.

(t *testing.T)

Source from the content-addressed store, hash-verified

27// FakeSMTPServer starts a minimal SMTP server that accepts messages.
28// Returns the address and a function to call to stop the server and get received messages.
29func FakeSMTPServer(t *testing.T) (SMTPAddr, func() []SMTPMessage) {
30 t.Helper()
31
32 listener, err := net.Listen("tcp", "127.0.0.1:0")
33 if err != nil {
34 t.Fatalf("FakeSMTPServer: listen: %v", err)
35 }
36
37 addr := listener.Addr().(*net.TCPAddr)
38 result := SMTPAddr{Host: addr.IP.String(), Port: addr.Port}
39
40 var mu sync.Mutex
41 var messages []SMTPMessage
42
43 go func() {
44 for {
45 conn, err := listener.Accept()
46 if err != nil {
47 return // listener closed
48 }
49 go handleSMTPConn(conn, &mu, &messages)
50 }
51 }()
52
53 t.Cleanup(func() { listener.Close() })
54
55 return result, func() []SMTPMessage {
56 listener.Close()
57 mu.Lock()
58 defer mu.Unlock()
59 out := make([]SMTPMessage, len(messages))
60 copy(out, messages)
61 return out
62 }
63}
64
65func handleSMTPConn(conn net.Conn, mu *sync.Mutex, messages *[]SMTPMessage) {
66 defer conn.Close()

Callers 4

setupWorkerFunction · 0.92
newNotifierFunction · 0.92
setupAPIWithSMTPFunction · 0.92
setupMagicLinkAPIFunction · 0.92

Calls 6

handleSMTPConnFunction · 0.85
makeFunction · 0.85
CleanupMethod · 0.80
copyFunction · 0.50
StringMethod · 0.45
CloseMethod · 0.45

Tested by 4

setupWorkerFunction · 0.74
newNotifierFunction · 0.74
setupAPIWithSMTPFunction · 0.74
setupMagicLinkAPIFunction · 0.74