mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-14 09:52:54 +01:00
Add failure test case for writing to temporary file
Added a new test case "TestMsg_WriteToTempFile_fail" in msg_test.go to validate the failure scenario when attempting to write a message to a non-existent temporary directory. This new test will ensure error handling is properly conducted in such situations.
This commit is contained in:
parent
f60ef348aa
commit
ba00d56168
1 changed files with 16 additions and 0 deletions
16
msg_test.go
16
msg_test.go
|
@ -2582,6 +2582,22 @@ func TestMsg_WriteToTempFile(t *testing.T) {
|
||||||
_ = os.Remove(f)
|
_ = os.Remove(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestMsg_WriteToTempFile_fail will test the output to temporary files
|
||||||
|
// with failure
|
||||||
|
func TestMsg_WriteToTempFile_fail(t *testing.T) {
|
||||||
|
m := NewMsg()
|
||||||
|
_ = m.From("Toni Tester <tester@example.com>")
|
||||||
|
_ = m.To("Ellenor Tester <ellinor@example.com>")
|
||||||
|
m.SetBodyString(TypeTextPlain, "This is a test")
|
||||||
|
_ = os.Setenv("TMPDIR", "/does/not/exist")
|
||||||
|
f, err := m.WriteToTempFile()
|
||||||
|
if err == nil {
|
||||||
|
t.Error("write message to temporary output file was supposed to fail, but didn't")
|
||||||
|
}
|
||||||
|
_ = os.Unsetenv("TMPDIR")
|
||||||
|
_ = os.Remove(f)
|
||||||
|
}
|
||||||
|
|
||||||
// TestMsg_WriteToFile will test the output to a file
|
// TestMsg_WriteToFile will test the output to a file
|
||||||
func TestMsg_WriteToFile(t *testing.T) {
|
func TestMsg_WriteToFile(t *testing.T) {
|
||||||
f, err := os.CreateTemp("", "go-mail-test_*.eml")
|
f, err := os.CreateTemp("", "go-mail-test_*.eml")
|
||||||
|
|
Loading…
Reference in a new issue