forge
Explore
Log in

Don't you dare go Hollow

Read the one clock in the meal past-day tests

Browse files at this commit

b1ef5941100b40cf2c43bb7aab08b2c426e35c9aAhmet Kaan GümüşParent: 4e4a808
  • fix
    • read the one clock in the meal past-day tests
Show full message
⏰ fix: read the one clock in the meal past-day tests

The two test helpers 7c5bc9d added read `chrono::Utc::now()` directly, which
`clippy.toml` denies: `Timestamp::now`/`today_utc` is the crate's single
wall-clock source, and that is what makes "no local/UTC mix" checkable at all.
A denied lint left standing in tests quietly retires the guard for the whole
crate.

Both go through `Timestamp::today_utc()` — which returns the `NaiveDate` these
wanted anyway — and yesterday is now `pred_opt()` rather than a `chrono::
Duration` subtraction. Same dates, one clock. No `#[allow]` was needed: the
crate-native helper covers both cases exactly.
src/domain/meal_booking.rsmodified+8 -5
@@ -1344,11 +1344,12 @@ mod tests {
1344 assert!(check_cutoff(&past, &lunch(), &cutoff(Some(60), Some(720))).is_err());1344 assert!(check_cutoff(&past, &lunch(), &cutoff(Some(60), Some(720))).is_err());
1345 }1345 }
1346 1346
1347+ /// Through the crate's one clock ([`Timestamp::today_utc`]), never
1348+ /// `chrono::Utc::now` — the guard under test compares against that same
1349+ /// clock, and a test reading a second one is how a timezone mix gets back
1350+ /// in (`clippy.toml` denies it, tests included).
1347 fn today() -> String {1351 fn today() -> String {
1348- chrono::Utc::now()1352+ Timestamp::today_utc().format("%Y-%m-%d").to_string()
1349- .date_naive()
1350- .format("%Y-%m-%d")
1351- .to_string()
1352 }1353 }
1353 1354
1354 /// The day being over is not the cutoff. It binds with no1355 /// The day being over is not the cutoff. It binds with no
@@ -1357,7 +1358,9 @@ mod tests {
1357 /// — and it never binds today, at any hour.1358 /// — and it never binds today, at any hour.
1358 #[test]1359 #[test]
1359 fn the_past_day_guard_is_not_the_serving_hour_cutoff() {1360 fn the_past_day_guard_is_not_the_serving_hour_cutoff() {
1360- let yesterday = (chrono::Utc::now().date_naive() - chrono::Duration::days(1))1361+ let yesterday = Timestamp::today_utc()
1362+ .pred_opt()
1363+ .expect("there is a day before today")
1361 .format("%Y-%m-%d")1364 .format("%Y-%m-%d")
1362 .to_string();1365 .to_string();
1363 assert!(check_day_not_past(&MenuDate::try_new(&yesterday).unwrap()).is_err());1366 assert!(check_day_not_past(&MenuDate::try_new(&yesterday).unwrap()).is_err());