diff options
Diffstat (limited to 'tests/db.rs')
| -rw-r--r-- | tests/db.rs | 56 |
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", - ¶ms(vec![pb]), - ); + let n: Option<i64> = env.query_i64("SELECT count(*) FROM candidate WHERE pkgbase_id=?1", ¶ms(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", ¶ms(vec![id]))) - .is_err(), + std::panic::catch_unwind(|| env.exec("UPDATE audit SET action='x' WHERE id=?1", ¶ms(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] |
