mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-23 02:50:39 +01:00
Add tests for the EmbedFile functionality in msg_test.go
This commit introduces three new test cases to validate the EmbedFile function in the msg_test.go file. The tests cover embedding an existing file, handling a non-existent file, and referencing pre-tested options.
This commit is contained in:
parent
d02f469658
commit
ae7b6a68c5
1 changed files with 42 additions and 0 deletions
42
msg_test.go
42
msg_test.go
|
@ -4787,7 +4787,49 @@ func TestMsg_AttachFromEmbedFS(t *testing.T) {
|
|||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestMsg_EmbedFile(t *testing.T) {
|
||||
t.Run("EmbedFile with file", func(t *testing.T) {
|
||||
message := NewMsg()
|
||||
if message == nil {
|
||||
t.Fatal("message is nil")
|
||||
}
|
||||
message.EmbedFile("testdata/embed.txt")
|
||||
embeds := message.GetEmbeds()
|
||||
if len(embeds) != 1 {
|
||||
t.Fatalf("failed to retrieve embeds list")
|
||||
}
|
||||
if embeds[0] == nil {
|
||||
t.Fatal("expected embed to be not nil")
|
||||
}
|
||||
if embeds[0].Name != "embed.txt" {
|
||||
t.Errorf("expected embed name to be %s, got: %s", "embed.txt", embeds[0].Name)
|
||||
}
|
||||
messageBuf := bytes.NewBuffer(nil)
|
||||
_, err := embeds[0].Writer(messageBuf)
|
||||
if err != nil {
|
||||
t.Errorf("writer func failed: %s", err)
|
||||
}
|
||||
got := strings.TrimSpace(messageBuf.String())
|
||||
if !strings.EqualFold(got, "This is a test embed") {
|
||||
t.Errorf("expected message body to be %s, got: %s", "This is a test embed", got)
|
||||
}
|
||||
})
|
||||
t.Run("EmbedFile with non-existant file", func(t *testing.T) {
|
||||
message := NewMsg()
|
||||
if message == nil {
|
||||
t.Fatal("message is nil")
|
||||
}
|
||||
message.EmbedFile("testdata/non-existant-file.txt")
|
||||
embeds := message.GetEmbeds()
|
||||
if len(embeds) != 0 {
|
||||
t.Fatalf("failed to retrieve attachments list")
|
||||
}
|
||||
})
|
||||
t.Run("EmbedFile with options", func(t *testing.T) {
|
||||
t.Log("all options have already been tested in file_test.go")
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue