summaryrefslogtreecommitdiffstats
path: root/src/db/model/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/model/mod.rs')
-rw-r--r--src/db/model/mod.rs28
1 files changed, 28 insertions, 0 deletions
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() }));
+ }
+}