From 52061f97c654834982f714df316bb76c759f7ae8 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 20 Sep 2024 20:58:29 +0200 Subject: [PATCH] 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. --- senderror_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/senderror_test.go b/senderror_test.go index 8b7bfb3..bf823e9 100644 --- a/senderror_test.go +++ b/senderror_test.go @@ -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()