mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +01:00
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:
parent
80bf7240b4
commit
ae44d37d03
1 changed files with 38 additions and 0 deletions
38
msg_test.go
38
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue