Skip to content

Commit

Permalink
allow no cron entries in cron plugin when enabled (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
jagonalez authored Apr 13, 2022
1 parent 32b4455 commit ce9027b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func (c *CronSubsystem) getOptions(s *server.Server) (*Options, error) {

cronJobsValue, ok := s.Options.GlobalConfig["cron"]
if !ok {
return &options, fmt.Errorf("getOptions: no cron jobs provided")
options.CronJobs = cronJobs
return &options, nil
}

if cronJobsInterface, ok := cronJobsValue.([]map[string]interface{}); ok {
Expand Down
26 changes: 26 additions & 0 deletions cron/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,32 @@ func TestCron(t *testing.T) {
assert.Equal(t, "test_job_2", jobTwo.Type)
})
})

t.Run("allows no cron jobs", func(t *testing.T) {
system := new(CronSubsystem)
configDir := createConfigDir(t)
runSystem(configDir, func(s *server.Server) {
s.Options.GlobalConfig["cron_plugin"] = map[string]interface{}{
"enabled": true,
}
err := system.Start(s)
assert.Nil(t, err)
assert.Len(t, system.Cron.Entries(), 0)
assert.True(t, system.Options.Enabled)
assert.Len(t, system.Options.CronJobs, 0)

cronJob := map[string]interface{}{
"schedule": "* * * * *",
"job": map[string]interface{}{
"type": "test_job",
},
}
cronConfig := []map[string]interface{}{cronJob}
s.Options.GlobalConfig["cron"] = cronConfig
system.Reload(s)
assert.Len(t, system.Cron.Entries(), 1)
})
})
}

func runSystem(configDir string, runner func(s *server.Server)) {
Expand Down

0 comments on commit ce9027b

Please sign in to comment.