mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 05:40:50 +01:00
Add deferred TMPDIR restoration in test setup
Store and restore the original TMPDIR value using a deferred function in `msg_nowin_test.go`. This ensures the TMPDIR environment variable is restored after the test runs, preventing potential side effects on other tests or processes.
This commit is contained in:
parent
4053457020
commit
0b9a215e7d
1 changed files with 7 additions and 0 deletions
|
@ -68,6 +68,13 @@ func TestMsg_WriteToTempFileFailed(t *testing.T) {
|
||||||
_ = m.To("Ellenor Tester <ellinor@example.com>")
|
_ = m.To("Ellenor Tester <ellinor@example.com>")
|
||||||
m.SetBodyString(TypeTextPlain, "This is a test")
|
m.SetBodyString(TypeTextPlain, "This is a test")
|
||||||
|
|
||||||
|
curTmpDir := os.Getenv("TMPDIR")
|
||||||
|
defer func() {
|
||||||
|
if err := os.Setenv("TMPDIR", curTmpDir); err != nil {
|
||||||
|
t.Errorf("failed to set TMPDIR environment variable: %s", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err := os.Setenv("TMPDIR", "/invalid/directory/that/does/not/exist"); err != nil {
|
if err := os.Setenv("TMPDIR", "/invalid/directory/that/does/not/exist"); err != nil {
|
||||||
t.Errorf("failed to set TMPDIR environment variable: %s", err)
|
t.Errorf("failed to set TMPDIR environment variable: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue