From d02f4696588aab63980ac099e72f1d91380e81e3 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 28 Oct 2024 11:35:05 +0100 Subject: [PATCH] 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. --- msg_test.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/msg_test.go b/msg_test.go index 9cab403..80bec04 100644 --- a/msg_test.go +++ b/msg_test.go @@ -4766,8 +4766,28 @@ func TestMsg_AttachFromEmbedFS(t *testing.T) { 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.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") + } + }) + } /*