Skip to content

Commit

Permalink
only validate check interval/cron when publish true (#3259)
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Porter <[email protected]>
  • Loading branch information
portertech authored and dabria committed Sep 6, 2019
1 parent 77c864e commit bb3c657
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 13 additions & 11 deletions api/core/v2/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,19 @@ func (c *Check) Validate() error {
if err := ValidateName(c.Name); err != nil {
return errors.New("check name " + err.Error())
}
if c.Cron != "" {
if c.Interval > 0 {
return errors.New("must only specify either an interval or a cron schedule")
}

if _, err := cron.ParseStandard(c.Cron); err != nil {
return errors.New("check cron string is invalid")
}
} else {
if c.Interval < 1 {
return errors.New("check interval must be greater than or equal to 1")
if c.Publish {
if c.Cron != "" {
if c.Interval > 0 {
return errors.New("must only specify either an interval or a cron schedule")
}

if _, err := cron.ParseStandard(c.Cron); err != nil {
return errors.New("check cron string is invalid")
}
} else {
if c.Interval < 1 {
return errors.New("check interval must be greater than or equal to 1")
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions api/core/v2/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func TestScheduleValidation(t *testing.T) {

c.Cron = "this is an invalid cron"
assert.Error(t, c.Validate())

c.Publish = false
assert.NoError(t, c.Validate())
}

func TestFixtureCheckIsValid(t *testing.T) {
Expand Down

0 comments on commit bb3c657

Please sign in to comment.