From 5b602be818d7cabfe11c08944d9706a7d19610e8 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sat, 26 Oct 2024 18:46:46 +0200 Subject: [PATCH] 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. --- msg_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/msg_test.go b/msg_test.go index aed62d8..9bf5f36 100644 --- a/msg_test.go +++ b/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" `) + }) + 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. // 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,