Compare commits

..

6 commits

Author SHA1 Message Date
b4aa414a4d
Update doc.go
Bump version to v0.5.2
2024-11-06 11:22:54 +01:00
0f46ce800e
Merge pull request #354 from wneessen/test_close_on_nil
Add test for closing a nil smtpclient
2024-11-06 10:55:59 +01:00
03e53cbabc
Merge branch 'main' into test_close_on_nil 2024-11-06 10:52:32 +01:00
632ac17845
Merge pull request #353 from sonalys/fix/close_panic
Fix(close): Access to nil variable causes panic
2024-11-06 10:51:53 +01:00
a5fcb3ae8b
Add test for closing a nil smtpclient
Introduce a unit test to ensure that invoking Close on a nil smtpclient instance returns nil without errors. This enhances the robustness of the client closure functionality. This test accommodates the fix provided with PR #353
2024-11-06 10:47:31 +01:00
Alysson Ribeiro
8c4eb62360
Fix(close): Access to nil variable causes panic 2024-11-06 10:20:59 +01:00
3 changed files with 11 additions and 2 deletions

View file

@ -996,7 +996,7 @@ func (c *Client) DialWithContext(dialCtx context.Context) error {
// Returns: // Returns:
// - An error if the disconnection fails; otherwise, returns nil. // - An error if the disconnection fails; otherwise, returns nil.
func (c *Client) Close() error { func (c *Client) Close() error {
if !c.smtpClient.HasConnection() { if c.smtpClient == nil || !c.smtpClient.HasConnection() {
return nil return nil
} }
if err := c.smtpClient.Quit(); err != nil { if err := c.smtpClient.Quit(); err != nil {

View file

@ -1647,6 +1647,15 @@ func TestClient_Close(t *testing.T) {
t.Errorf("close was supposed to fail, but didn't") t.Errorf("close was supposed to fail, but didn't")
} }
}) })
t.Run("close on a nil smtpclient should return nil", func(t *testing.T) {
client, err := NewClient(DefaultHost)
if err != nil {
t.Fatalf("failed to create new client: %s", err)
}
if err = client.Close(); err != nil {
t.Errorf("failed to close the client: %s", err)
}
})
} }
func TestClient_DialWithContext(t *testing.T) { func TestClient_DialWithContext(t *testing.T) {

2
doc.go
View file

@ -11,4 +11,4 @@ package mail
// VERSION indicates the current version of the package. It is also attached to the default user // VERSION indicates the current version of the package. It is also attached to the default user
// agent string. // agent string.
const VERSION = "0.5.1" const VERSION = "0.5.2"