forked from dagu-org/dagu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Email attachment testcase (Fixes dagu-org#812)
- Loading branch information
Showing
3 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package executor | |
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/dagu-org/dagu/internal/digraph" | ||
|
@@ -12,9 +13,22 @@ import ( | |
func TestMail(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Create temporary directory for test files | ||
tmpDir, err := os.MkdirTemp("", "email-test") | ||
if err != nil { | ||
t.Fatalf("failed to create temp dir: %v", err) | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
// Create a test email attachment | ||
attachFile := filepath.Join(tmpDir, "email.txt") | ||
content := []byte("Test email") | ||
|
||
os.Setenv("MAIL_SUBJECT", "Test Subject") | ||
os.WriteFile(attachFile, content, 0644) | ||
t.Cleanup(func() { | ||
os.Unsetenv("MAIL_SUBJECT") | ||
os.Remove(attachFile) | ||
}) | ||
|
||
t.Run("NewMail", func(t *testing.T) { | ||
|
@@ -27,10 +41,11 @@ func TestMail(t *testing.T) { | |
step: digraph.Step{ | ||
ExecutorConfig: digraph.ExecutorConfig{ | ||
Config: map[string]any{ | ||
"from": "[email protected]", | ||
"to": "[email protected]", | ||
"subject": "Test Subject", | ||
"message": "Test Message", | ||
"from": "[email protected]", | ||
"to": "[email protected]", | ||
"subject": "Test Subject", | ||
"message": "Test Message", | ||
"attachments": attachFile, | ||
}, | ||
}, | ||
}, | ||
|
@@ -40,10 +55,11 @@ func TestMail(t *testing.T) { | |
step: digraph.Step{ | ||
ExecutorConfig: digraph.ExecutorConfig{ | ||
Config: map[string]any{ | ||
"from": "[email protected]", | ||
"to": "[email protected]", | ||
"subject": "${MAIL_SUBJECT}", | ||
"message": "Test Message", | ||
"from": "[email protected]", | ||
"to": "[email protected]", | ||
"subject": "${MAIL_SUBJECT}", | ||
"message": "Test Message", | ||
"attachments": attachFile, | ||
}, | ||
}, | ||
}, | ||
|
@@ -68,6 +84,7 @@ func TestMail(t *testing.T) { | |
assert.Equal(t, "[email protected]", mailExec.cfg.To) | ||
assert.Equal(t, "Test Subject", mailExec.cfg.Subject) | ||
assert.Equal(t, "Test Message", mailExec.cfg.Message) | ||
assert.Equal(t, attachFile, mailExec.cfg.Attachments[0]) | ||
}) | ||
} | ||
}) | ||
|