Skip to content

fix(utils): centralize cron expression validation (closes #863)#916

Open
belnoinja wants to merge 1 commit into
goharbor:mainfrom
belnoinja:feat/central-cron-validation
Open

fix(utils): centralize cron expression validation (closes #863)#916
belnoinja wants to merge 1 commit into
goharbor:mainfrom
belnoinja:feat/central-cron-validation

Conversation

@belnoinja
Copy link
Copy Markdown

Closes #863

Cron expression validation was duplicated in two private functions:

  • validateCronExpression in pkg/views/scan-all/update/view.go
  • validateCron in cmd/harbor/root/scan_all/update_schedule.go

This PR centralizes the logic into a single reusable utils.ValidateCronExpression(expr string) error function in pkg/utils/cron.go and replaces both inline implementations with calls to it.

Changes

  • pkg/utils/cron.go — new file with ValidateCronExpression, mirrors exact existing regex and field-count behavior, no new dependencies
  • pkg/utils/cron_test.go — 14 table-driven tests (valid expressions, empty input, wrong field counts, out-of-range values)
  • pkg/views/scan-all/update/view.go — removed private validateCronExpression, passes utils.ValidateCronExpression directly to huh form Validate callback
  • cmd/harbor/root/scan_all/update_schedule.go — removed private validateCron and unused errors import, delegates to utils.ValidateCronExpression

Testing

go build ./...   # exit 0
go test ./...    # all tests pass
go vet ./...     # exit 0

Signed-off-by: Naman <jainnaman9450035045@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature]: Central Cron Expression Validation

1 participant