Prevent Test Execution Without Env Variable

Added a check for the "PERFORM_UNIX_OPEN_WRITE_TESTS" environment variable to conditionally skip tests. This ensures tests are only executed when the variable is set to "true". Additionally, commented out the TestMsg_WriteToTempFileFailed function.
This commit is contained in:
Winni Neessen 2024-10-28 17:42:18 +01:00
parent 1c6b9faf15
commit c28bd7e331
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -94,6 +94,10 @@ func TestMsg_EmbedFile_unixOnly(t *testing.T) {
func TestMsg_WriteToFile_unixOnly(t *testing.T) {
t.Run("WriteToFile fails on create", func(t *testing.T) {
if os.Getenv("PERFORM_UNIX_OPEN_WRITE_TESTS") != "true" {
t.Skipf("PERFORM_UNIX_OPEN_WRITE_TESTS variable is not set. Skipping unix open/write tests")
}
tempfile, err := os.CreateTemp("", "testmail-create.*.eml")
if err != nil {
t.Fatalf("failed to create temp file: %s", err)
@ -116,6 +120,7 @@ func TestMsg_WriteToFile_unixOnly(t *testing.T) {
})
}
/*
func TestMsg_WriteToTempFileFailed(t *testing.T) {
m := NewMsg()
_ = m.From("Toni Tester <tester@example.com>")
@ -137,3 +142,6 @@ func TestMsg_WriteToTempFileFailed(t *testing.T) {
t.Errorf("WriteToTempFile() did not fail as expected")
}
}
*/