mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +01:00
Add tests for ReplyToFormat method
Implement new tests for the Msg.ReplyToFormat method to ensure it correctly handles both valid and invalid email addresses. These tests validate the ReplyTo header formatting and error handling.
This commit is contained in:
parent
96d45c26bc
commit
5b602be818
1 changed files with 22 additions and 0 deletions
22
msg_test.go
22
msg_test.go
|
@ -1540,6 +1540,28 @@ func TestMsg_ReplyTo(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMsg_ReplyToFormat(t *testing.T) {
|
||||||
|
t.Run("ReplyToFormat with valid address", func(t *testing.T) {
|
||||||
|
message := NewMsg()
|
||||||
|
if message == nil {
|
||||||
|
t.Fatal("message is nil")
|
||||||
|
}
|
||||||
|
if err := message.ReplyToFormat("Tina Tester", "tina.tester@example.com"); err != nil {
|
||||||
|
t.Fatalf("failed to set ReplyTo: %s", err)
|
||||||
|
}
|
||||||
|
checkGenHeader(t, message, HeaderReplyTo, "ReplyToFormat", 0, 1, `"Tina Tester" <tina.tester@example.com>`)
|
||||||
|
})
|
||||||
|
t.Run("ReplyToFormat with invalid address", func(t *testing.T) {
|
||||||
|
message := NewMsg()
|
||||||
|
if message == nil {
|
||||||
|
t.Fatal("message is nil")
|
||||||
|
}
|
||||||
|
if err := message.ReplyToFormat("Invalid", "invalid"); err == nil {
|
||||||
|
t.Errorf("ReplyToFormat should fail with invalid address")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// checkAddrHeader verifies the correctness of an AddrHeader in a Msg based on the provided criteria.
|
// checkAddrHeader verifies the correctness of an AddrHeader in a Msg based on the provided criteria.
|
||||||
// It checks whether the AddrHeader contains the correct address, name, and number of fields.
|
// It checks whether the AddrHeader contains the correct address, name, and number of fields.
|
||||||
func checkAddrHeader(t *testing.T, message *Msg, header AddrHeader, fn string, field, wantFields int,
|
func checkAddrHeader(t *testing.T, message *Msg, header AddrHeader, fn string, field, wantFields int,
|
||||||
|
|
Loading…
Reference in a new issue