Add test cases for AttachFromEmbedFS errors

Introduce two new test cases for the AttachFromEmbedFS method. These tests verify that the method correctly handles an invalid file path and a nil embed FS, ensuring error scenarios are properly managed.
This commit is contained in:
Winni Neessen 2024-10-28 11:35:05 +01:00
parent e779777c9b
commit d02f469658
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -4766,8 +4766,28 @@ func TestMsg_AttachFromEmbedFS(t *testing.T) {
if !strings.EqualFold(got, "This is a test attachment") { if !strings.EqualFold(got, "This is a test attachment") {
t.Errorf("expected message body to be %s, got: %s", "This is a test attachment", got) t.Errorf("expected message body to be %s, got: %s", "This is a test attachment", got)
} }
}) })
t.Run("AttachFromEmbedFS with invalid path", func(t *testing.T) {
message := NewMsg()
if message == nil {
t.Fatal("message is nil")
}
err := message.AttachFromEmbedFS("testdata/invalid.txt", &efs, WithFileName("attachment.txt"))
if err == nil {
t.Fatal("expected error, got nil")
}
})
t.Run("AttachFromEmbedFS with nil embed FS", func(t *testing.T) {
message := NewMsg()
if message == nil {
t.Fatal("message is nil")
}
err := message.AttachFromEmbedFS("testdata/invalid.txt", nil, WithFileName("attachment.txt"))
if err == nil {
t.Fatal("expected error, got nil")
}
})
} }
/* /*