Add tests for nil SendError MessageID and Msg

These tests ensure that accessing MessageID and Msg methods on a nil SendError pointer returns the expected values (empty string and nil respectively). This helps in validating the error handling logic and avoiding potential nil pointer dereference issues.
This commit is contained in:
Winni Neessen 2024-09-20 20:58:29 +02:00
parent 77920be1a1
commit 52061f97c6
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -108,6 +108,13 @@ func TestSendError_MessageID(t *testing.T) {
}
}
func TestSendError_MessageIDNil(t *testing.T) {
var se *SendError
if se.MessageID() != "" {
t.Error("expected empty string on nil-senderror")
}
}
func TestSendError_Msg(t *testing.T) {
var se *SendError
err := returnSendError(ErrAmbiguous, false)
@ -131,6 +138,13 @@ func TestSendError_Msg(t *testing.T) {
}
}
func TestSendError_MsgNil(t *testing.T) {
var se *SendError
if se.Msg() != nil {
t.Error("expected nil on nil-senderror")
}
}
// returnSendError is a helper method to retunr a SendError with a specific reason
func returnSendError(r SendErrReason, t bool) error {
message := NewMsg()