MCPcopy Index your code
hub / github.com/foxcpp/maddy / SMTPServer

Function SMTPServer

internal/testutils/smtp_server.go:203–235  ·  view source on GitHub ↗
(t *testing.T, addr string, fn ...SMTPServerConfigureFunc)

Source from the content-addressed store, hash-verified

201type SMTPServerConfigureFunc func(*smtp.Server)
202
203func SMTPServer(t *testing.T, addr string, fn ...SMTPServerConfigureFunc) (*SMTPBackend, *smtp.Server) {
204 t.Helper()
205
206 l, err := net.Listen("tcp", addr)
207 if err != nil {
208 t.Fatal(err)
209 }
210
211 be := new(SMTPBackend)
212 s := smtp.NewServer(be)
213 s.Domain = "localhost"
214 s.AllowInsecureAuth = true
215 for _, f := range fn {
216 f(s)
217 }
218
219 go func() {
220 if err := s.Serve(l); err != nil {
221 t.Error(err)
222 }
223 }()
224
225 // Dial it once it make sure Server completes its initialization before
226 // we try to use it. Notably, if test fails before connecting to the server,
227 // it will call Server.Close which will call Server.listener.Close with a
228 // nil Server.listener (Serve sets it to a non-nil value, so it is racy and
229 // happens only sometimes).
230 testConn, err := net.Dial("tcp", addr)
231 require.NoError(t, err)
232 require.NoError(t, testConn.Close())
233
234 return be, s
235}
236
237// RSA 1024, valid for *.example.invalid, 127.0.0.1, 127.0.0.2,, 127.0.0.3
238// until Nov 18 17:13:45 2029 GMT.

Callers 6

TestSMTPUTF8Function · 0.92
TestLMTPClient_Issue308Function · 0.92
TestMTA_OutboundFunction · 0.92
TestIssue321Function · 0.92
TestIssue327Function · 0.92

Calls 3

ListenMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by 6

TestSMTPUTF8Function · 0.74
TestLMTPClient_Issue308Function · 0.74
TestMTA_OutboundFunction · 0.74
TestIssue321Function · 0.74
TestIssue327Function · 0.74