From 9d4078919717559c90e40736917603401135437c Mon Sep 17 00:00:00 2001 From: aur-build Date: Fri, 20 Nov 2026 20:24:47 +0000 Subject: hash, time, db::model: move the pure clock and digest tests home MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tests/hash.rs held three tests and none of them belonged there. Two were about `canonical_json` and moved into src/hash.rs. The third asserted that the identity digest is a pure function of an identity's own fields — a property of `db::model::Identity`, not of the hashing helper it happens to call — so it moved to db::model, where the thing it tests lives. The file is now empty and is deleted; the tests are moves, not losses, and each is named in its new module. tests/time.rs held three tests, two of which were clock arithmetic with no dependencies at all. They moved into src/time.rs. The third pins a build lease against a pinned clock and needs a database, so it stayed where a database is available. No visibility changed in this commit: `canonical_json` is used in production and stays public, and `time::pin`/`unpin` are ungated test escapes that the disposition table will decide on rather than being quietly narrowed here as a side effect. Suite: 281 passed, 0 failed, 0 ignored. Release build: zero warnings. --- src/db/model/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/db/model') diff --git a/src/db/model/mod.rs b/src/db/model/mod.rs index acfcda5..7c1fbf5 100644 --- a/src/db/model/mod.rs +++ b/src/db/model/mod.rs @@ -206,3 +206,31 @@ pub(crate) use state::StateEnum; pub use build_state::{BUILD_STEPS, BuildState, StepState}; pub use state::{CandidateState, ReleaseState, SubscriptionState, candidate_kind, notice_kind}; + +#[cfg(test)] +mod tests { + use super::*; + + // Moved verbatim from tests/hash.rs, where it sat next to the canonical + // JSON tests but asserted nothing about hashing: it pins the contract that + // the identity digest is a pure function of the identity's own fields. + // That is a property of `Identity`, so it lives with `Identity`. + + #[test] + fn the_identity_digest_is_a_function_of_the_identity_alone() { + let base = Identity { + aur_commit: "cafe123".into(), + epoch: "0".into(), + pkgver: "1.2.3".into(), + pkgrel: "1".into(), + upstream_pins: vec![], + source_digests: vec![], + }; + let digest = |i: &Identity| i.hash().unwrap(); + assert!(digest(&base).starts_with("sha256:")); + assert_eq!(digest(&base), digest(&base.clone()), "the same identity hashed twice, twice differently"); + assert_ne!(digest(&base), digest(&Identity { pkgrel: "2".into(), ..base.clone() })); + assert_ne!(digest(&base), digest(&Identity { epoch: "1".into(), ..base.clone() })); + assert_ne!(digest(&base), digest(&Identity { aur_commit: "cafe124".into(), ..base.clone() })); + } +} -- cgit v1.2.3