Skip to content

Commit fc0674c

Browse files
test: fix vacuous assertions in src/fuzzy_schedule.rs (#1512)
Rewrite two low-value tests that only checked enum discriminants via matches! without verifying the cron expressions they generate: - test_parse_hourly: add cron structure assertions (5 fields, scattered minute in [0,59], correct * wildcards for hourly) - test_parse_special_periods: add cron step assertions (*/14 for bi-weekly, */21 for tri-weekly) plus bounds checks on the scattered minute/hour values Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 74aa011 commit fc0674c

1 file changed

Lines changed: 42 additions & 12 deletions

File tree

src/fuzzy_schedule.rs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -856,10 +856,20 @@ mod tests {
856856

857857
#[test]
858858
fn test_parse_hourly() {
859-
assert!(matches!(
860-
parse_fuzzy_schedule("hourly").unwrap(),
861-
FuzzySchedule::Hourly
862-
));
859+
let schedule = parse_fuzzy_schedule("hourly").unwrap();
860+
assert!(matches!(schedule, FuzzySchedule::Hourly));
861+
// Cron must be "M * * * *" — every hour at a hash-scattered minute.
862+
// A regression that emits "0 * * * *" (fixed minute) or changes the
863+
// field count would silently break the scattering contract.
864+
let cron = generate_cron(&schedule, "test/workflow");
865+
let parts: Vec<&str> = cron.split_whitespace().collect();
866+
assert_eq!(parts.len(), 5, "Hourly cron must have 5 fields");
867+
let minute: u32 = parts[0].parse().expect("minute field must be a number");
868+
assert!(minute < 60, "Scattered minute must be in [0, 59], got {minute}");
869+
assert_eq!(parts[1], "*", "Hour field must be * for hourly schedule");
870+
assert_eq!(parts[2], "*", "Day-of-month must be * for hourly schedule");
871+
assert_eq!(parts[3], "*", "Month must be * for hourly schedule");
872+
assert_eq!(parts[4], "*", "Day-of-week must be * for hourly schedule");
863873
}
864874

865875
#[test]
@@ -884,14 +894,34 @@ mod tests {
884894

885895
#[test]
886896
fn test_parse_special_periods() {
887-
assert!(matches!(
888-
parse_fuzzy_schedule("bi-weekly").unwrap(),
889-
FuzzySchedule::BiWeekly
890-
));
891-
assert!(matches!(
892-
parse_fuzzy_schedule("tri-weekly").unwrap(),
893-
FuzzySchedule::TriWeekly
894-
));
897+
// Verify parse and cron structure for bi-weekly and tri-weekly schedules.
898+
// The key assertion is the day-of-month step (*/14 / */21) — a regression
899+
// that swaps these or omits the step would silently change schedule frequency.
900+
let bi = parse_fuzzy_schedule("bi-weekly").unwrap();
901+
assert!(matches!(bi, FuzzySchedule::BiWeekly));
902+
let bi_cron = generate_cron(&bi, "test/workflow");
903+
let bi_parts: Vec<&str> = bi_cron.split_whitespace().collect();
904+
assert_eq!(bi_parts.len(), 5, "Bi-weekly cron must have 5 fields");
905+
let bi_min: u32 = bi_parts[0].parse().expect("minute field must be a number");
906+
assert!(bi_min < 60, "Scattered minute must be in [0, 59], got {bi_min}");
907+
let bi_hr: u32 = bi_parts[1].parse().expect("hour field must be a number");
908+
assert!(bi_hr < 24, "Scattered hour must be in [0, 23], got {bi_hr}");
909+
assert_eq!(bi_parts[2], "*/14", "Bi-weekly step must be */14");
910+
assert_eq!(bi_parts[3], "*");
911+
assert_eq!(bi_parts[4], "*");
912+
913+
let tri = parse_fuzzy_schedule("tri-weekly").unwrap();
914+
assert!(matches!(tri, FuzzySchedule::TriWeekly));
915+
let tri_cron = generate_cron(&tri, "test/workflow");
916+
let tri_parts: Vec<&str> = tri_cron.split_whitespace().collect();
917+
assert_eq!(tri_parts.len(), 5, "Tri-weekly cron must have 5 fields");
918+
let tri_min: u32 = tri_parts[0].parse().expect("minute field must be a number");
919+
assert!(tri_min < 60, "Scattered minute must be in [0, 59], got {tri_min}");
920+
let tri_hr: u32 = tri_parts[1].parse().expect("hour field must be a number");
921+
assert!(tri_hr < 24, "Scattered hour must be in [0, 23], got {tri_hr}");
922+
assert_eq!(tri_parts[2], "*/21", "Tri-weekly step must be */21");
923+
assert_eq!(tri_parts[3], "*");
924+
assert_eq!(tri_parts[4], "*");
895925
}
896926

897927
#[test]

0 commit comments

Comments
 (0)