summaryrefslogtreecommitdiffstats
path: root/tests/db.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-22 10:36:24 +0000
committeraur-build <aur-build@localhost>2026-11-22 10:36:24 +0000
commit3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 (patch)
tree7cc7169181b4bdd73fd8817f8c1d7cce6e6998a8 /tests/db.rs
parent9dc9087d89891c6e5ef7e5dc084dd13c8611843e (diff)
downloadaur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.tar.gz
aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.zip
rustfmt,lints: pin the formatting, adopt the idiom lints, pay them off
rustfmt.toml fixes the shape the tree is written in (120 columns, small items kept on one line) and one canonical pass makes it the truth. [lints.clippy] names the idiom lints worth enforcing and leaves out the two that would add doc-comment boilerplate rather than remove it. The tree pays them off here: write!/writeln! instead of push_str(&format!()), let-else instead of match-on-Option, borrows where a thread entry point only reads what it owns, no `&self` on a Copy state and no `self` nobody reads. ops::to_prometheus gains one gauge helper: a metric's HELP, TYPE and value are now emitted by the same call instead of three.
Diffstat (limited to 'tests/db.rs')
-rw-r--r--tests/db.rs56
1 files changed, 11 insertions, 45 deletions
diff --git a/tests/db.rs b/tests/db.rs
index d91e5f5..755472e 100644
--- a/tests/db.rs
+++ b/tests/db.rs
@@ -6,15 +6,7 @@ use rusqlite::params;
use aur_build::db;
fn insert_snapshot(env: &Env, pkgbase_id: i64, commit: &str) -> i64 {
- db::put_snapshot(
- &env.db.writer,
- pkgbase_id,
- commit,
- &format!("rh-{commit}"),
- "{}",
- "[]",
- )
- .unwrap()
+ db::put_snapshot(&env.db.writer, pkgbase_id, commit, &format!("rh-{commit}"), "{}", "[]").unwrap()
}
fn insert_candidate(env: &Env, pkgbase_id: i64, snap_id: i64, identity: &str, state: &str) {
@@ -28,18 +20,10 @@ fn insert_candidate(env: &Env, pkgbase_id: i64, snap_id: i64, identity: &str, st
#[test]
fn migrations_apply_from_empty_and_are_idempotent() {
let env = Env::new();
- let v = env
- .db
- .read(|c| {
- Ok(c.pragma_query_value(None, "user_version", |r| r.get::<_, u32>(0))?)
- })
- .unwrap();
+ let v = env.db.read(|c| Ok(c.pragma_query_value(None, "user_version", |r| r.get::<_, u32>(0))?)).unwrap();
assert_eq!(v as usize, db::MIGRATIONS.len(), "all migrations applied");
assert_eq!(db::migrate(&env.cfg.db_path()).unwrap(), 0);
- let journal: String = env
- .db
- .read(|c| Ok(c.pragma_query_value(None, "journal_mode", |r| r.get(0))?))
- .unwrap();
+ let journal: String = env.db.read(|c| Ok(c.pragma_query_value(None, "journal_mode", |r| r.get(0))?)).unwrap();
assert_eq!(journal.to_lowercase(), "wal", "WAL mode");
}
@@ -66,10 +50,7 @@ fn i7_second_open_review_is_rejected_by_the_database() {
assert!(err.is_err(), "second pending_review must fail");
insert_candidate(&env, pb, snap2, "id-2", "rejected");
- let n: Option<i64> = env.query_i64(
- "SELECT count(*) FROM candidate WHERE pkgbase_id=?1",
- &params(vec![pb]),
- );
+ let n: Option<i64> = env.query_i64("SELECT count(*) FROM candidate WHERE pkgbase_id=?1", &params(vec![pb]));
assert_eq!(n, Some(2));
}
@@ -88,13 +69,9 @@ fn candidate_identity_is_unique_per_pkgbase() {
fn audit_log_is_append_only() {
let env = Env::new();
db::audit_system(&env.db.writer, "test", "pkgbase", "1", serde_json::json!({"k": 1})).unwrap();
- let id = env
- .query_i64("SELECT id FROM audit ORDER BY id DESC LIMIT 1", &[])
- .unwrap();
+ let id = env.query_i64("SELECT id FROM audit ORDER BY id DESC LIMIT 1", &[]).unwrap();
assert!(
- std::panic::catch_unwind(|| env
- .exec("UPDATE audit SET action='x' WHERE id=?1", &params(vec![id])))
- .is_err(),
+ std::panic::catch_unwind(|| env.exec("UPDATE audit SET action='x' WHERE id=?1", &params(vec![id]))).is_err(),
"audit UPDATE must be refused by trigger"
);
assert!(
@@ -124,10 +101,7 @@ fn accepted_release_pointer_is_compared_and_swapped() {
.unwrap();
assert!(db::cas_accepted_release(&env.db.writer, pb, None, rel).unwrap());
assert!(!db::cas_accepted_release(&env.db.writer, pb, None, rel).unwrap());
- assert_eq!(
- db::get_pkgbase(&env.db, "foo").unwrap().unwrap().current_accepted_release_id,
- Some(rel)
- );
+ assert_eq!(db::get_pkgbase(&env.db, "foo").unwrap().unwrap().current_accepted_release_id, Some(rel));
}
#[test]
@@ -182,19 +156,11 @@ fn duplicate_open_notices_are_suppressed() {
let env = Env::new();
let pb = env.subscribe("foo");
let detail = serde_json::json!({"old": "a", "new": "b"});
- assert!(db::put_notice_once(&env.db.writer, pb, "pin_drift", "info", detail.clone())
- .unwrap()
- .is_some());
- assert!(db::put_notice_once(&env.db.writer, pb, "pin_drift", "info", detail.clone())
- .unwrap()
- .is_none());
- let id = env
- .query_i64("SELECT id FROM notice ORDER BY id DESC LIMIT 1", &[])
- .unwrap();
+ assert!(db::put_notice_once(&env.db.writer, pb, "pin_drift", "info", &detail).unwrap().is_some());
+ assert!(db::put_notice_once(&env.db.writer, pb, "pin_drift", "info", &detail).unwrap().is_none());
+ let id = env.query_i64("SELECT id FROM notice ORDER BY id DESC LIMIT 1", &[]).unwrap();
db::acknowledge_notice(&env.db.writer, id).unwrap();
- assert!(db::put_notice_once(&env.db.writer, pb, "pin_drift", "info", detail)
- .unwrap()
- .is_some());
+ assert!(db::put_notice_once(&env.db.writer, pb, "pin_drift", "info", &detail).unwrap().is_some());
}
#[test]