From d16ae61f64547b62c74ea5e976799d01525d7a5a Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sat, 26 Oct 2024 22:53:30 +0200 Subject: [PATCH] Add test for GetAddrHeader with multiple valid addresses Introduce a new test to validate the behavior of GetAddrHeader for handling multiple addresses (to, cc, bcc). This test ensures that the function correctly processes and returns the expected addresses in various headers. --- msg_test.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/msg_test.go b/msg_test.go index 0c3c441..f622359 100644 --- a/msg_test.go +++ b/msg_test.go @@ -2444,6 +2444,59 @@ func TestMsg_GetAddrHeader(t *testing.T) { }) } }) + t.Run("GetAddrHeader with multiple valid address (to, cc, bcc)", func(t *testing.T) { + var fn func(...string) error + var addfn func(string) error + for _, tt := range addrHeaderTests { + message := NewMsg() + if message == nil { + t.Fatal("message is nil") + } + + switch tt.header { + case HeaderFrom: + continue + case HeaderTo: + fn = message.To + addfn = message.AddTo + case HeaderCc: + fn = message.Cc + addfn = message.AddCc + case HeaderBcc: + fn = message.Bcc + addfn = message.AddBcc + default: + t.Logf("header %s not supported", tt.header) + continue + } + t.Run(tt.name, func(t *testing.T) { + if err := fn("toni.tester@example.com"); err != nil { + t.Fatalf("failed to set header: %s", err) + } + if err := addfn("tina.tester@example.com"); err != nil { + t.Fatalf("failed to set additional header value: %s", err) + } + addrheader := message.GetAddrHeader(tt.header) + if len(addrheader) != 2 { + t.Errorf("GetAddrHeader: expected 1 address, got: %d", len(addrheader)) + } + if addrheader[0] == nil { + t.Fatalf("GetAddrHeader: expected address, got nil") + } + if addrheader[0].String() != "" { + t.Errorf("GetAddrHeader: expected address not returned. Want: %s, got: %s", + "", addrheader[0].String()) + } + if addrheader[1] == nil { + t.Fatalf("GetAddrHeader: expected address, got nil") + } + if addrheader[1].String() != "" { + t.Errorf("GetAddrHeader: expected address not returned. Want: %s, got: %s", + "", addrheader[1].String()) + } + }) + } + }) t.Run("GetAddrHeader with no addresses", func(t *testing.T) { message := NewMsg() if message == nil {