From df1a141368817e08b3c5d1cc379e3030b5377e9d Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 22 Oct 2024 16:02:43 +0200 Subject: [PATCH] Handle client close errors in SMTP tests Update defer statements to log errors if client fails to close in smtp_test.go. Additionally, add a return statement to avoid further errors after a failed SendMail operation. --- smtp/smtp_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/smtp/smtp_test.go b/smtp/smtp_test.go index cb134ba..737bd58 100644 --- a/smtp/smtp_test.go +++ b/smtp/smtp_test.go @@ -417,7 +417,11 @@ func TestXOAuth2OK(t *testing.T) { if err != nil { t.Fatalf("NewClient: %v", err) } - defer c.Close() + defer func() { + if err := c.Close(); err != nil { + t.Errorf("failed to close client: %s", err) + } + }() auth := XOAuth2Auth("user", "token") err = c.Auth(auth) @@ -455,7 +459,11 @@ func TestXOAuth2Error(t *testing.T) { if err != nil { t.Fatalf("NewClient: %v", err) } - defer c.Close() + defer func() { + if err := c.Close(); err != nil { + t.Errorf("failed to close client: %s", err) + } + }() auth := XOAuth2Auth("user", "token") err = c.Auth(auth) @@ -1631,6 +1639,7 @@ SendMail is working for me. `, "\n", "\r\n", -1))) if err == nil { t.Error("SendMail: Server doesn't support AUTH, expected to get an error, but got none ") + return } if err.Error() != "smtp: server doesn't support AUTH" { t.Errorf("Expected: smtp: server doesn't support AUTH, got: %s", err)