From f3633e1913b923e68b6fd004a02a95c9744a54ee Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 20 Sep 2024 21:11:19 +0200 Subject: [PATCH] Add tests for SendError functionalities Introduce tests for `SendError` to verify behavior of `errors.Is` and string representation. `TestSendError_IsFail` checks for error mismatch, and `TestSendError_ErrorMulti` verifies the formatted error message. --- senderror_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/senderror_test.go b/senderror_test.go index bf823e9..9a9b1ec 100644 --- a/senderror_test.go +++ b/senderror_test.go @@ -145,6 +145,24 @@ func TestSendError_MsgNil(t *testing.T) { } } +func TestSendError_IsFail(t *testing.T) { + err1 := returnSendError(ErrAmbiguous, false) + err2 := returnSendError(ErrSMTPMailFrom, false) + if errors.Is(err1, err2) { + t.Errorf("error mismatch, ErrAmbiguous should not be equal to ErrSMTPMailFrom") + } +} + +func TestSendError_ErrorMulti(t *testing.T) { + expected := `ambiguous reason, check Msg.SendError for message specific reasons, ` + + `affected recipient(s): , ` + err := &SendError{Reason: ErrAmbiguous, isTemp: false, affectedMsg: nil, + rcpt: []string{"", ""}} + if err.Error() != expected { + t.Errorf("error mismatch, expected: %s, got: %s", expected, err.Error()) + } +} + // returnSendError is a helper method to retunr a SendError with a specific reason func returnSendError(r SendErrReason, t bool) error { message := NewMsg()