Skip to content

Commit

Permalink
Merge branch 'v2' into dependabot/github_actions/golangci/golangci-li…
Browse files Browse the repository at this point in the history
…nt-action-6.1.1
  • Loading branch information
JohnRoesler authored Oct 31, 2024
2 parents ea8d882 + a47779d commit c02a857
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var (
ErrDailyJobAtTimeNil = fmt.Errorf("gocron: DailyJob: atTime within atTimes must not be nil")
ErrDailyJobAtTimesNil = fmt.Errorf("gocron: DailyJob: atTimes must not be nil")
ErrDailyJobHours = fmt.Errorf("gocron: DailyJob: atTimes hours must be between 0 and 23 inclusive")
ErrDailyJobZeroInterval = fmt.Errorf("gocron: DailyJob: interval must be greater than 0")
ErrDailyJobMinutesSeconds = fmt.Errorf("gocron: DailyJob: atTimes minutes and seconds must be between 0 and 59 inclusive")
ErrDurationJobIntervalZero = fmt.Errorf("gocron: DurationJob: time interval is 0")
ErrDurationRandomJobMinMax = fmt.Errorf("gocron: DurationRandomJob: minimum duration must be less than maximum duration")
Expand All @@ -20,6 +21,7 @@ var (
ErrMonthlyJobAtTimesNil = fmt.Errorf("gocron: MonthlyJob: atTimes must not be nil")
ErrMonthlyJobDaysNil = fmt.Errorf("gocron: MonthlyJob: daysOfTheMonth must not be nil")
ErrMonthlyJobHours = fmt.Errorf("gocron: MonthlyJob: atTimes hours must be between 0 and 23 inclusive")
ErrMonthlyJobZeroInterval = fmt.Errorf("gocron: MonthlyJob: interval must be greater than 0")
ErrMonthlyJobMinutesSeconds = fmt.Errorf("gocron: MonthlyJob: atTimes minutes and seconds must be between 0 and 59 inclusive")
ErrNewJobTaskNil = fmt.Errorf("gocron: NewJob: Task must not be nil")
ErrNewJobTaskNotFunc = fmt.Errorf("gocron: NewJob: Task.Function must be of kind reflect.Func")
Expand All @@ -33,6 +35,7 @@ var (
ErrWeeklyJobAtTimesNil = fmt.Errorf("gocron: WeeklyJob: atTimes must not be nil")
ErrWeeklyJobDaysOfTheWeekNil = fmt.Errorf("gocron: WeeklyJob: daysOfTheWeek must not be nil")
ErrWeeklyJobHours = fmt.Errorf("gocron: WeeklyJob: atTimes hours must be between 0 and 23 inclusive")
ErrWeeklyJobZeroInterval = fmt.Errorf("gocron: WeeklyJob: interval must be greater than 0")
ErrWeeklyJobMinutesSeconds = fmt.Errorf("gocron: WeeklyJob: atTimes minutes and seconds must be between 0 and 59 inclusive")
ErrPanicRecovered = fmt.Errorf("gocron: panic recovered")
ErrWithClockNil = fmt.Errorf("gocron: WithClock: clock must not be nil")
Expand Down
10 changes: 10 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ func (d dailyJobDefinition) setup(j *internalJob, location *time.Location, _ tim
return ErrDailyJobMinutesSeconds
}

if d.interval == 0 {
return ErrDailyJobZeroInterval
}

ds := dailyJob{
interval: d.interval,
atTimes: atTimesDate,
Expand All @@ -270,6 +274,9 @@ type weeklyJobDefinition struct {

func (w weeklyJobDefinition) setup(j *internalJob, location *time.Location, _ time.Time) error {
var ws weeklyJob
if w.interval == 0 {
return ErrWeeklyJobZeroInterval
}
ws.interval = w.interval

if w.daysOfTheWeek == nil {
Expand Down Expand Up @@ -335,6 +342,9 @@ type monthlyJobDefinition struct {

func (m monthlyJobDefinition) setup(j *internalJob, location *time.Location, _ time.Time) error {
var ms monthlyJob
if m.interval == 0 {
return ErrMonthlyJobZeroInterval
}
ms.interval = m.interval

if m.daysOfTheMonth == nil {
Expand Down
15 changes: 15 additions & 0 deletions mocks/job.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions mocks/scheduler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,17 @@ func TestScheduler_NewJobErrors(t *testing.T) {
nil,
ErrDailyJobMinutesSeconds,
},
{
"daily job interval 0",
DailyJob(
0,
NewAtTimes(
NewAtTime(1, 0, 0),
),
),
nil,
ErrDailyJobZeroInterval,
},
{
"weekly job at times nil",
WeeklyJob(
Expand Down Expand Up @@ -675,6 +686,18 @@ func TestScheduler_NewJobErrors(t *testing.T) {
nil,
ErrWeeklyJobMinutesSeconds,
},
{
"weekly job interval zero",
WeeklyJob(
0,
NewWeekdays(time.Monday),
NewAtTimes(
NewAtTime(1, 0, 0),
),
),
nil,
ErrWeeklyJobZeroInterval,
},
{
"monthly job at times nil",
MonthlyJob(
Expand Down Expand Up @@ -755,6 +778,18 @@ func TestScheduler_NewJobErrors(t *testing.T) {
nil,
ErrMonthlyJobMinutesSeconds,
},
{
"monthly job interval zero",
MonthlyJob(
0,
NewDaysOfTheMonth(1),
NewAtTimes(
NewAtTime(1, 0, 0),
),
),
nil,
ErrMonthlyJobZeroInterval,
},
{
"WithName no name",
DurationJob(
Expand Down

0 comments on commit c02a857

Please sign in to comment.