mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-13 21:56:38 +01:00
fix(flags): detect schedule set from env (#1373)
This commit is contained in:
parent
e04a107694
commit
f047d75dcc
2 changed files with 43 additions and 11 deletions
|
|
@ -143,8 +143,8 @@ func TestProcessFlagAliases(t *testing.T) {
|
|||
RegisterNotificationFlags(cmd)
|
||||
|
||||
require.NoError(t, cmd.ParseFlags([]string{
|
||||
`--porcelain`, `v1`,
|
||||
`--interval`, `10`,
|
||||
`--porcelain`, `v1`,
|
||||
`--interval`, `10`,
|
||||
}))
|
||||
flags := cmd.Flags()
|
||||
ProcessFlagAliases(flags)
|
||||
|
|
@ -173,7 +173,7 @@ func TestProcessFlagAliasesSchedAndInterval(t *testing.T) {
|
|||
RegisterSystemFlags(cmd)
|
||||
RegisterNotificationFlags(cmd)
|
||||
|
||||
require.NoError(t, cmd.ParseFlags([]string{`--schedule`, `@now`, `--interval`, `10`}))
|
||||
require.NoError(t, cmd.ParseFlags([]string{`--schedule`, `@hourly`, `--interval`, `10`}))
|
||||
flags := cmd.Flags()
|
||||
|
||||
assert.PanicsWithValue(t, `FATAL`, func() {
|
||||
|
|
@ -181,6 +181,26 @@ func TestProcessFlagAliasesSchedAndInterval(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestProcessFlagAliasesScheduleFromEnvironment(t *testing.T) {
|
||||
cmd := new(cobra.Command)
|
||||
|
||||
err := os.Setenv("WATCHTOWER_SCHEDULE", `@hourly`)
|
||||
require.NoError(t, err)
|
||||
defer os.Unsetenv("WATCHTOWER_SCHEDULE")
|
||||
|
||||
SetDefaults()
|
||||
RegisterDockerFlags(cmd)
|
||||
RegisterSystemFlags(cmd)
|
||||
RegisterNotificationFlags(cmd)
|
||||
|
||||
require.NoError(t, cmd.ParseFlags([]string{}))
|
||||
flags := cmd.Flags()
|
||||
ProcessFlagAliases(flags)
|
||||
|
||||
sched, _ := flags.GetString(`schedule`)
|
||||
assert.Equal(t, `@hourly`, sched)
|
||||
}
|
||||
|
||||
func TestProcessFlagAliasesInvalidPorcelaineVersion(t *testing.T) {
|
||||
logrus.StandardLogger().ExitFunc = func(_ int) { panic(`FATAL`) }
|
||||
cmd := new(cobra.Command)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue