mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-23 02:50:39 +01:00
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.
This commit is contained in:
parent
5e5bcef696
commit
d16ae61f64
1 changed files with 53 additions and 0 deletions
53
msg_test.go
53
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() != "<toni.tester@example.com>" {
|
||||
t.Errorf("GetAddrHeader: expected address not returned. Want: %s, got: %s",
|
||||
"<toni.tester@example.com>", addrheader[0].String())
|
||||
}
|
||||
if addrheader[1] == nil {
|
||||
t.Fatalf("GetAddrHeader: expected address, got nil")
|
||||
}
|
||||
if addrheader[1].String() != "<tina.tester@example.com>" {
|
||||
t.Errorf("GetAddrHeader: expected address not returned. Want: %s, got: %s",
|
||||
"<tina.tester@example.com>", addrheader[1].String())
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
t.Run("GetAddrHeader with no addresses", func(t *testing.T) {
|
||||
message := NewMsg()
|
||||
if message == nil {
|
||||
|
|
Loading…
Reference in a new issue