-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from yohamta/fix/add-default-env
fix: add $HOME as a default environment variables
- Loading branch information
Showing
11 changed files
with
49 additions
and
223 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,21 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"sort" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/yohamta/dagu/internal/constants" | ||
"github.com/yohamta/dagu/internal/utils" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
l := &Loader{ | ||
HomeDir: utils.MustGetUserHomeDir(), | ||
} | ||
cfg, err := l.Load(testConfig, "") | ||
_, err := l.Load(testConfig, "") | ||
require.NoError(t, err) | ||
|
||
steps := []*Step{ | ||
{ | ||
Name: "1", | ||
Dir: testHomeDir, | ||
CmdWithArgs: "true", | ||
Command: "true", | ||
Args: []string{}, | ||
Variables: testEnv, | ||
Preconditions: []*Condition{ | ||
{ | ||
Condition: "`echo test`", | ||
Expected: "test", | ||
}, | ||
}, | ||
MailOnError: true, | ||
ContinueOn: ContinueOn{ | ||
Failure: true, | ||
Skipped: true, | ||
}, | ||
RetryPolicy: &RetryPolicy{ | ||
Limit: 2, | ||
}, | ||
RepeatPolicy: RepeatPolicy{ | ||
Repeat: true, | ||
Interval: time.Second * 10, | ||
}, | ||
}, | ||
{ | ||
Name: "2", | ||
Dir: testDir, | ||
CmdWithArgs: "false", | ||
Command: "false", | ||
Args: []string{}, | ||
Variables: testEnv, | ||
Preconditions: []*Condition{}, | ||
ContinueOn: ContinueOn{ | ||
Failure: true, | ||
Skipped: false, | ||
}, | ||
Depends: []string{ | ||
"1", | ||
}, | ||
}, | ||
} | ||
|
||
makeTestStepFunc := func(name string) *Step { | ||
c := fmt.Sprintf("%s.sh", name) | ||
return &Step{ | ||
Name: name, | ||
Dir: testDir, | ||
CmdWithArgs: c, | ||
Command: c, | ||
Args: []string{}, | ||
Variables: testEnv, | ||
Preconditions: []*Condition{}, | ||
} | ||
} | ||
|
||
stepm := map[string]*Step{} | ||
for _, name := range []string{ | ||
constants.OnExit, | ||
constants.OnSuccess, | ||
constants.OnFailure, | ||
constants.OnCancel, | ||
} { | ||
stepm[name] = makeTestStepFunc(name) | ||
} | ||
|
||
want := &Config{ | ||
ConfigPath: testConfig, | ||
Name: "test DAG", | ||
Description: "this is a test DAG.", | ||
Env: testEnv, | ||
LogDir: path.Join(testHomeDir, "/logs"), | ||
HistRetentionDays: 3, | ||
MailOn: MailOn{ | ||
Failure: true, | ||
Success: true, | ||
}, | ||
Delay: time.Second * 1, | ||
MaxActiveRuns: 1, | ||
Params: []string{"param1", "param2"}, | ||
DefaultParams: "param1 param2", | ||
Smtp: &SmtpConfig{ | ||
Host: "smtp.host", | ||
Port: "25", | ||
}, | ||
ErrorMail: &MailConfig{ | ||
From: "[email protected]", | ||
To: "[email protected]", | ||
Prefix: "[ERROR]", | ||
}, | ||
InfoMail: &MailConfig{ | ||
From: "[email protected]", | ||
To: "[email protected]", | ||
Prefix: "[INFO]", | ||
}, | ||
Preconditions: []*Condition{ | ||
{ | ||
Condition: "`echo 1`", | ||
Expected: "1", | ||
}, | ||
}, | ||
Steps: steps, | ||
HandlerOn: HandlerOn{ | ||
Exit: stepm[constants.OnExit], | ||
Success: stepm[constants.OnSuccess], | ||
Failure: stepm[constants.OnFailure], | ||
Cancel: stepm[constants.OnCancel], | ||
}, | ||
MaxCleanUpTime: time.Second * 500, | ||
} | ||
assert.Equal(t, want, cfg) | ||
} | ||
|
||
func TestLoadGlobalConfig(t *testing.T) { | ||
|
@@ -146,34 +28,6 @@ func TestLoadGlobalConfig(t *testing.T) { | |
) | ||
require.NotNil(t, cfg) | ||
require.NoError(t, err) | ||
|
||
sort.Slice(cfg.Env, func(i, j int) bool { | ||
return strings.Compare(cfg.Env[i], cfg.Env[j]) < 0 | ||
}) | ||
|
||
want := &Config{ | ||
Env: testEnv, | ||
LogDir: path.Join(testHomeDir, "/logs"), | ||
HistRetentionDays: 7, | ||
Params: []string{}, | ||
Steps: []*Step{}, | ||
Smtp: &SmtpConfig{ | ||
Host: "smtp.host", | ||
Port: "25", | ||
}, | ||
ErrorMail: &MailConfig{ | ||
From: "[email protected]", | ||
To: "[email protected]", | ||
Prefix: "[ERROR]", | ||
}, | ||
InfoMail: &MailConfig{ | ||
From: "[email protected]", | ||
To: "[email protected]", | ||
Prefix: "[INFO]", | ||
}, | ||
Preconditions: []*Condition{}, | ||
} | ||
assert.Equal(t, want, cfg) | ||
} | ||
|
||
func TestLoadGlobalConfigError(t *testing.T) { | ||
|
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,4 @@ | ||
name: "test" | ||
steps: | ||
- name: "1" | ||
command: "false" |
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