From 44df830348d99ebedef2ceb356d4b4b2e4a939b2 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 20 Sep 2024 17:00:08 +0200 Subject: [PATCH] Add tests for SendError MessageID and Msg methods 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. --- senderror_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/senderror_test.go b/senderror_test.go index 789b290..8b7bfb3 100644 --- a/senderror_test.go +++ b/senderror_test.go @@ -90,7 +90,55 @@ func TestSendError_IsTempNil(t *testing.T) { } } +func TestSendError_MessageID(t *testing.T) { + var se *SendError + err := returnSendError(ErrAmbiguous, false) + if !errors.As(err, &se) { + t.Errorf("error mismatch, expected error to be of type *SendError") + return + } + if errors.As(err, &se) { + if se.MessageID() == "" { + t.Errorf("sendError expected message-id, but got empty string") + } + if !strings.EqualFold(se.MessageID(), "") { + t.Errorf("sendError message-id expected: %s, but got: %s", "", + se.MessageID()) + } + } +} + +func TestSendError_Msg(t *testing.T) { + var se *SendError + err := returnSendError(ErrAmbiguous, false) + if !errors.As(err, &se) { + t.Errorf("error mismatch, expected error to be of type *SendError") + return + } + if errors.As(err, &se) { + if se.Msg() == nil { + t.Errorf("sendError expected msg pointer, but got nil") + } + from := se.Msg().GetFromString() + if len(from) == 0 { + t.Errorf("sendError expected msg from, but got empty string") + return + } + if !strings.EqualFold(from[0], "") { + t.Errorf("sendError message from expected: %s, but got: %s", "", + from[0]) + } + } +} + // returnSendError is a helper method to retunr a SendError with a specific reason func returnSendError(r SendErrReason, t bool) error { - return &SendError{Reason: r, isTemp: t} + message := NewMsg() + _ = message.From("toni.tester@domain.tld") + _ = message.To("tina.tester@domain.tld") + message.Subject("This is the subject") + message.SetBodyString(TypeTextPlain, "This is the message body") + message.SetMessageIDWithValue("this.is.a.message.id") + + return &SendError{Reason: r, isTemp: t, affectedMsg: message} }