-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
163 additions
and
38 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
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
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package executors | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/dagu-org/dagu/internal/digraph" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMail(t *testing.T) { | ||
t.Parallel() | ||
|
||
os.Setenv("MAIL_SUBJECT", "Test Subject") | ||
t.Cleanup(func() { | ||
os.Unsetenv("MAIL_SUBJECT") | ||
}) | ||
|
||
t.Run("NewMail", func(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
step digraph.Step | ||
expectedError bool | ||
}{ | ||
{ | ||
name: "ValidConfig", | ||
step: digraph.Step{ | ||
ExecutorConfig: digraph.ExecutorConfig{ | ||
Config: map[string]any{ | ||
"from": "[email protected]", | ||
"to": "[email protected]", | ||
"subject": "Test Subject", | ||
"message": "Test Message", | ||
}, | ||
}, | ||
}, | ||
expectedError: false, | ||
}, | ||
{ | ||
name: "ValidConfigWithEnv", | ||
step: digraph.Step{ | ||
ExecutorConfig: digraph.ExecutorConfig{ | ||
Config: map[string]any{ | ||
"from": "[email protected]", | ||
"to": "[email protected]", | ||
"subject": "${MAIL_SUBJECT}", | ||
"message": "Test Message", | ||
}, | ||
}, | ||
}, | ||
expectedError: false, | ||
}, | ||
{ | ||
name: "InvalidConfig", | ||
step: digraph.Step{ | ||
ExecutorConfig: digraph.ExecutorConfig{ | ||
Config: map[string]any{ | ||
"from": "[email protected]", | ||
}, | ||
}, | ||
}, | ||
expectedError: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctx := context.Background() | ||
ctx = digraph.NewContext(ctx, &digraph.DAG{ | ||
SMTP: &digraph.SMTPConfig{}, | ||
}, nil, nil, "", "") | ||
|
||
exec, err := newMail(ctx, tt.step) | ||
|
||
if tt.expectedError { | ||
assert.Error(t, err) | ||
assert.Nil(t, exec) | ||
} else { | ||
assert.NoError(t, err) | ||
assert.NotNil(t, exec) | ||
|
||
mailExec, ok := exec.(*mail) | ||
assert.True(t, ok) | ||
assert.Equal(t, "[email protected]", mailExec.cfg.From) | ||
assert.Equal(t, "[email protected]", mailExec.cfg.To) | ||
assert.Equal(t, "Test Subject", mailExec.cfg.Subject) | ||
assert.Equal(t, "Test Message", mailExec.cfg.Message) | ||
} | ||
}) | ||
} | ||
}) | ||
} |
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