mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-22 10:40:39 +01:00
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.
This commit is contained in:
parent
4ee11e8406
commit
44df830348
1 changed files with 49 additions and 1 deletions
|
@ -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(), "<this.is.a.message.id>") {
|
||||
t.Errorf("sendError message-id expected: %s, but got: %s", "<this.is.a.message.id>",
|
||||
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], "<toni.tester@domain.tld>") {
|
||||
t.Errorf("sendError message from expected: %s, but got: %s", "<toni.tester@domain.tld>",
|
||||
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}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue