MCPcopy Create free account
hub / github.com/foxcpp/maddy / TestSMTPDeliver_CheckError_Deferred

Function TestSMTPDeliver_CheckError_Deferred

internal/endpoint/smtp/smtp_test.go:316–368  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

314}
315
316func TestSMTPDeliver_CheckError_Deferred(t *testing.T) {
317 tgt := testutils.Target{}
318 endp := testEndpoint(t, "smtp", nil, &tgt, []module.Check{
319 &testutils.Check{
320 ConnRes: module.CheckResult{
321 Reason: &exterrors.SMTPError{
322 Code: 523,
323 Message: "Hey",
324 },
325 Reject: true,
326 },
327 },
328 }, nil)
329 endp.deferServerReject = true
330 defer func() {
331 assert.NoError(t, endp.Stop())
332 }()
333
334 cl, err := smtp.Dial("127.0.0.1:" + testPort)
335 if err != nil {
336 t.Fatal(err)
337 }
338 defer func() {
339 assert.NoError(t, cl.Close())
340 }()
341
342 err = cl.Mail("sender@example.org", nil)
343 if err != nil {
344 t.Fatal(err)
345 }
346
347 checkErr := func(err error) {
348 if err == nil {
349 t.Fatal("Expected an error, got none")
350 }
351 smtpErr, ok := err.(*smtp.SMTPError)
352 if !ok {
353 t.Error("Non-SMTPError returned")
354 return
355 }
356
357 if smtpErr.Code != 523 {
358 t.Error("Wrong SMTP code:", smtpErr.Code)
359 }
360 if !strings.HasPrefix(smtpErr.Message, "Hey") {
361 t.Error("Wrong SMTP message:", smtpErr.Message)
362 }
363 }
364
365 checkErr(cl.Rcpt("test1@example.org", &smtp.RcptOptions{}))
366 checkErr(cl.Rcpt("test1@example.org", &smtp.RcptOptions{}))
367 checkErr(cl.Rcpt("test2@example.org", &smtp.RcptOptions{}))
368}
369
370func TestSMTPDelivery_Multi(t *testing.T) {
371 tgt := testutils.Target{}

Callers

nothing calls this directly

Calls 6

testEndpointFunction · 0.85
StopMethod · 0.65
CloseMethod · 0.65
MailMethod · 0.45
ErrorMethod · 0.45
RcptMethod · 0.45

Tested by

no test coverage detected