summaryrefslogtreecommitdiffstats
path: root/tests/hash.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-20 20:24:47 +0000
committeraur-build <aur-build@localhost>2026-11-20 20:24:47 +0000
commit9d4078919717559c90e40736917603401135437c (patch)
tree7479b0782fa03365f3e7c440c30bbdec90acb0e7 /tests/hash.rs
parent8426843087178cac55c3dcea52aea3baccc29b69 (diff)
downloadaur-build-9d4078919717559c90e40736917603401135437c.tar.gz
aur-build-9d4078919717559c90e40736917603401135437c.zip
hash, time, db::model: move the pure clock and digest tests home
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.
Diffstat (limited to 'tests/hash.rs')
-rw-r--r--tests/hash.rs65
1 files changed, 0 insertions, 65 deletions
diff --git a/tests/hash.rs b/tests/hash.rs
deleted file mode 100644
index 32995ff..0000000
--- a/tests/hash.rs
+++ /dev/null
@@ -1,65 +0,0 @@
-use std::collections::HashMap;
-
-use aur_build::db::model::Identity;
-use aur_build::hash;
-
-struct Unserializable;
-
-impl serde::Serialize for Unserializable {
- fn serialize<S: serde::Serializer>(&self, _s: S) -> Result<S::Ok, S::Error> {
- Err(serde::ser::Error::custom("this value cannot be serialized"))
- }
-}
-
-#[test]
-fn a_value_that_cannot_be_serialized_is_an_error_not_an_empty_object() {
- let err = hash::canonical_json(&Unserializable).unwrap_err();
- assert!(err.to_string().contains("cannot be serialized"), "the failure was swallowed: {err}");
- assert!(hash::canonical_json(&Unserializable).is_err());
-}
-
-#[test]
-fn the_rendering_is_canonical_in_fact_not_in_name() {
- #[derive(serde::Serialize)]
- struct Ab {
- alpha: String,
- beta: String,
- }
- #[derive(serde::Serialize)]
- struct Ba {
- beta: String,
- alpha: String,
- }
- let ab = hash::canonical_json(&Ab { alpha: "1".into(), beta: "2".into() }).unwrap();
- let ba = hash::canonical_json(&Ba { beta: "2".into(), alpha: "1".into() }).unwrap();
- assert_eq!(ab, ba, "field declaration order leaked into the rendering: {ab} vs {ba}");
- assert_eq!(ab, r#"{"alpha":"1","beta":"2"}"#, "not the compact sorted rendering");
-
- let mut one = HashMap::new();
- one.insert("z", 1);
- one.insert("m", 2);
- one.insert("a", 3);
- let mut two = HashMap::new();
- two.insert("a", 3);
- two.insert("m", 2);
- two.insert("z", 1);
- assert_eq!(hash::canonical_json(&one).unwrap(), hash::canonical_json(&two).unwrap());
-}
-
-#[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 hash_of = |i: &Identity| i.hash().unwrap();
- assert!(hash_of(&base).starts_with("sha256:"));
- assert_eq!(hash_of(&base), hash_of(&base.clone()), "the same identity hashed twice, twice differently");
- assert_ne!(hash_of(&base), hash_of(&Identity { pkgrel: "2".into(), ..base.clone() }));
- assert_ne!(hash_of(&base), hash_of(&Identity { epoch: "1".into(), ..base.clone() }));
- assert_ne!(hash_of(&base), hash_of(&Identity { aur_commit: "cafe124".into(), ..base.clone() }));
-}