From a5fcb3ae8bd9ea47e932093bfa6ac629a9166412 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 6 Nov 2024 10:47:31 +0100 Subject: [PATCH] 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 --- client_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client_test.go b/client_test.go index 664f0fd..96ebf1f 100644 --- a/client_test.go +++ b/client_test.go @@ -1647,6 +1647,15 @@ func TestClient_Close(t *testing.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) {