From ae44d37d03939bc671c684a2d9aacc52bc7cc4f8 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 28 Oct 2024 12:30:13 +0100 Subject: [PATCH] Add test for Msg_Reset function This test ensures that the Reset method correctly clears all fields in the Msg struct. It verifies that the From, To, Subject, Body, Attachments, and Embeds fields are empty after calling Reset. --- msg_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/msg_test.go b/msg_test.go index 78382e8..42682b5 100644 --- a/msg_test.go +++ b/msg_test.go @@ -5104,6 +5104,44 @@ func TestMsg_EmbedFromEmbedFS(t *testing.T) { }) } +func TestMsg_Reset(t *testing.T) { + message := NewMsg() + if message == nil { + t.Fatal("message is nil") + } + if err := message.From("toni.tester@example.com"); err != nil { + t.Fatalf("failed to set From address: %s", err) + } + if err := message.To("tina.tester@example.com"); err != nil { + t.Fatalf("failed to set To address: %s", err) + } + message.Subject("This is the subject") + message.SetBodyString(TypeTextPlain, "This is the body") + message.AddAlternativeString(TypeTextPlain, "This is the alternative string") + message.EmbedFile("testdata/embed.txt") + message.AttachFile("testdata/attach.txt") + + message.Reset() + if len(message.GetFromString()) != 0 { + t.Errorf("expected message From address to be empty, got: %+v", message.GetFromString()) + } + if len(message.GetToString()) != 0 { + t.Errorf("expected message To address to be empty, got: %+v", message.GetFromString()) + } + if len(message.GetGenHeader(HeaderSubject)) != 0 { + t.Errorf("expected message Subject to be empty, got: %+v", message.GetGenHeader(HeaderSubject)) + } + if len(message.GetAttachments()) != 0 { + t.Errorf("expected message Attachments to be empty, got: %d", len(message.GetAttachments())) + } + if len(message.GetEmbeds()) != 0 { + t.Errorf("expected message Embeds to be empty, got: %d", len(message.GetEmbeds())) + } + if len(message.GetParts()) != 0 { + t.Errorf("expected message Parts to be empty, got: %d", len(message.GetParts())) + } +} + /* // TestNewMsgWithMiddleware tests WithMiddleware