From 75c0e3319be3ab43833c9864d993297f74984837 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 26 Nov 2024 16:26:13 +0100 Subject: [PATCH] Simplify attachment test setup Removed temporary file creation and copying in msgwriter_test.go. Directly attach the source file during the test to streamline the setup process. This change reduces complexity and potential points of failure in the test code. --- msgwriter_test.go | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/msgwriter_test.go b/msgwriter_test.go index 31aae21..d72c40c 100644 --- a/msgwriter_test.go +++ b/msgwriter_test.go @@ -10,7 +10,6 @@ import ( "fmt" "io" "mime" - "os" "runtime" "strings" "testing" @@ -342,30 +341,7 @@ func TestMsgWriter_addFiles(t *testing.T) { buffer := bytes.NewBuffer(nil) msgwriter.writer = buffer message := testMessage(t) - tmpfile, err := os.CreateTemp("", "attachment.*.tmp") - if err != nil { - t.Fatalf("failed to create tempfile: %s", err) - } - t.Cleanup(func() { - if err = os.Remove(tmpfile.Name()); err != nil { - t.Errorf("failed to remove tempfile: %s", err) - } - }) - - source, err := os.Open("testdata/attachment.txt") - if err != nil { - t.Fatalf("failed to open source file: %s", err) - } - if _, err = io.Copy(tmpfile, source); err != nil { - t.Fatalf("failed to copy source file: %s", err) - } - if err = tmpfile.Close(); err != nil { - t.Fatalf("failed to close tempfile: %s", err) - } - if err = source.Close(); err != nil { - t.Fatalf("failed to close source file: %s", err) - } - message.AttachFile(tmpfile.Name(), WithFileName(tt.filename)) + message.AttachFile("testdata/attachment.txt", WithFileName(tt.filename)) msgwriter.writeMsg(message) if msgwriter.err != nil { t.Errorf("msgWriter failed to write: %s", msgwriter.err)