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.
This commit is contained in:
Winni Neessen 2024-10-28 12:30:13 +01:00
parent 80bf7240b4
commit ae44d37d03
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -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 // TestNewMsgWithMiddleware tests WithMiddleware