Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved client error testing #302

Merged
merged 11 commits into from
Sep 20, 2024
Merged

Improved client error testing #302

merged 11 commits into from
Sep 20, 2024

Conversation

wneessen
Copy link
Owner

This PR introduces a simple test SMTP server that can be used to more granuarly test different error scenarios, that are hard to simulate with a real mail server. More tests for the Client have been added as well, these should also test some SendError functionality.

Additionally two new SendError methods have been added (as suggested by @mitar in #301 (comment)) :

  • MessageID(): returns the message ID of the affected Msg
  • Msg(): returns a pointer to the affectes Msg

Implemented a simple SMTP test server to facilitate unit testing. This server listens on a specified address and port, accepts connections, and processes common SMTP commands like HELO, MAIL FROM, RCPT TO, DATA, and QUIT. Several constants related to the server configuration were also added to the test file.
Implement MessageID and Msg methods in SendError to allow retrieval of the message ID and the affected message, respectively. These methods handle cases where the error or the message is nil, returning an empty string or nil as appropriate.
Introduced `TestClient_SendErrorNoEncoding` to verify client behavior when sending a message without encoding. Adjusted server connection handling for better error reporting and connection closure, replacing abrupt exits with returns where appropriate.
Implemented multiple tests to cover various error scenarios in the SMTP client, including invalid email addresses and data transmission failures. Introduced `failReset` flag in `simpleSMTPServer` to simulate server reset failures.
This test checks the client's ability to handle SMTP reset errors when sending an email. It verifies the correct error type, ensures it is recognized as a permanent error, and confirms the correct message ID handling.
Replaced `err == io.EOF` with `errors.Is(err, io.EOF)` for better error comparison. Removed redundant `break` statements to streamline case logic and improve code readability.
Removed unnecessary comments that were clarifying the purpose of sleep statements in the test cases. This makes the code cleaner and easier to maintain by reducing clutter.
Removed Go 1.21 and added Go 1.19 in the codecov.yml file to ensure compatibility with older projects and streamline the CI process. This helps in maintaining backward compatibility and avoids potential issues with unsupported Go versions.
Refine Send method to correctly typecast and accumulate SendError instances. Introduce "errors" package import to utilize errors.As for precise error type checking, ensuring accurate error lists. This regression was introduced with PR #301
Modified tests to dynamically compute server ports from a base value, enhancing flexibility and preventing potential conflicts. Updated `simpleSMTPServer` function to accept a port parameter.
Copy link

codecov bot commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 86.33%. Comparing base (619318b) to head (44df830).
Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
senderror.go 50.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #302      +/-   ##
==========================================
+ Coverage   85.37%   86.33%   +0.96%     
==========================================
  Files          25       25              
  Lines        2092     2100       +8     
==========================================
+ Hits         1786     1813      +27     
+ Misses        181      167      -14     
+ Partials      125      120       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Introduce two new tests in senderror_test.go: TestSendError_MessageID and TestSendError_Msg. These tests validate the behavior of the MessageID and Msg methods of the SendError type, ensuring correct handling of message ID and sender information.
@wneessen wneessen merged commit 6f869e4 into main Sep 20, 2024
22 of 23 checks passed
@wneessen wneessen deleted the feature/improve-client-tests branch September 20, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant