diff options
Diffstat (limited to 'tests/invariants.rs')
| -rw-r--r-- | tests/invariants.rs | 90 |
1 files changed, 22 insertions, 68 deletions
diff --git a/tests/invariants.rs b/tests/invariants.rs index 4bfffc8..d7a0f6f 100644 --- a/tests/invariants.rs +++ b/tests/invariants.rs @@ -23,15 +23,13 @@ fn query_pairs(env: &Env, sql: &str) -> Vec<(String, String)> { .read(move |c| { let mut st = c.prepare(sql)?; let rows = st.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))?; - Ok(rows.filter_map(|r| r.ok()).collect()) + Ok(rows.filter_map(std::result::Result::ok).collect()) }) .unwrap() } fn count(env: &Env, sql: &str) -> i64 { - env.db - .read(move |c| Ok(c.query_row(sql, [], |r| r.get::<_, i64>(0))?)) - .unwrap() + env.db.read(move |c| Ok(c.query_row(sql, [], |r| r.get::<_, i64>(0))?)).unwrap() } #[test] @@ -49,10 +47,7 @@ fn i1_every_index_entry_traces_back_to_an_approval() { 0, "an index entry exists that no human approved" ); - assert_eq!( - count(&env, "SELECT count(*) FROM approval WHERE decision='approved'"), - 1 - ); + assert_eq!(count(&env, "SELECT count(*) FROM approval WHERE decision='approved'"), 1); assert_eq!(count(&env, "SELECT count(*) FROM release WHERE approval_id IS NULL"), 0); } @@ -97,16 +92,9 @@ fn i4_kill_mid_publish_leaves_the_old_index_byte_identical() { do_approve(&env.db, "tester", c.id, &c.identity_hash, &dd, None).unwrap(); let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap(); env.set_publish_fault("before-rename"); - assert!(matches!( - pipeline::run(&env.cfg, &env.db, &id).unwrap(), - pipeline::Outcome::Failed { .. } - )); + assert!(matches!(pipeline::run(&env.cfg, &env.db, &id).unwrap(), pipeline::Outcome::Failed { .. })); - assert_eq!( - std::fs::read(&db_file).unwrap(), - old_bytes, - "the served index was torn by a crash" - ); + assert_eq!(std::fs::read(&db_file).unwrap(), old_bytes, "the served index was torn by a crash"); assert_eq!( query_pairs(&env, "SELECT name, version FROM package WHERE state='in_index'"), vec![("plain-make".to_string(), "1.0-1".to_string())] @@ -128,10 +116,7 @@ fn i5_resume_after_a_crash_repeats_no_completed_step() { let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap(); env.set_publish_fault("before-rename"); - assert!(matches!( - pipeline::run(&env.cfg, &env.db, &id).unwrap(), - pipeline::Outcome::Failed { .. } - )); + assert!(matches!(pipeline::run(&env.cfg, &env.db, &id).unwrap(), pipeline::Outcome::Failed { .. })); let shim = env.cfg.hooks.shim_dir.clone().unwrap(); let builds_before = aur_build::shims::called_with(&shim, "makepkg", ""); assert_eq!(builds_before, 2, "one build per attempted publish"); @@ -141,11 +126,7 @@ fn i5_resume_after_a_crash_repeats_no_completed_step() { pipeline::Outcome::Succeeded { release_id } => assert!(release_id > 0), other => panic!("{other:?}"), } - assert_eq!( - aur_build::shims::called_with(&shim, "makepkg", ""), - builds_before, - "resuming re-ran the build step" - ); + assert_eq!(aur_build::shims::called_with(&shim, "makepkg", ""), builds_before, "resuming re-ran the build step"); assert_eq!(count(&env, "SELECT count(*) FROM release WHERE pkgver='2.0'"), 1); assert_eq!( count(&env, "SELECT count(*) FROM artifact"), @@ -155,11 +136,9 @@ fn i5_resume_after_a_crash_repeats_no_completed_step() { let bad = env .db .read(|c| { - Ok(c.query_row( - "SELECT count(*) FROM build_step WHERE status NOT IN ('succeeded','skipped')", - [], - |r| r.get::<_, i64>(0), - )?) + Ok(c.query_row("SELECT count(*) FROM build_step WHERE status NOT IN ('succeeded','skipped')", [], |r| { + r.get::<_, i64>(0) + })?) }) .unwrap(); assert_eq!(bad, 0, "every step reached a terminal state"); @@ -205,17 +184,11 @@ fn i8_index_equals_the_accepted_pointers() { FROM pkgbase p JOIN release r ON r.id = p.current_accepted_release_id", ); - let index = query_pairs( - &env, - "SELECT name, version FROM package WHERE state='in_index'", - ); - assert!(!pointers.is_empty()); + let index = query_pairs(&env, "SELECT name, version FROM package WHERE state='in_index'"); + assert_ne!(pointers, [] as [(std::string::String, std::string::String); 0]); assert_eq!(index, pointers, "index and accepted pointers diverge"); - assert_eq!( - count(&env, "SELECT count(*) FROM package WHERE state='in_index' AND version='1.0-1'"), - 0 - ); + assert_eq!(count(&env, "SELECT count(*) FROM package WHERE state='in_index' AND version='1.0-1'"), 0); let db_file = env.cfg.repo_arch_dir().join("aur-build.db.tar.gz"); let names = index_db_names(&db_file); assert_eq!(names, vec!["plain-make".to_string()]); @@ -228,10 +201,7 @@ fn i3_materialization_fails_closed_on_the_recipe_pin() { let c = candidates::pending_candidates(&env.db).unwrap().remove(0); let dd = diff::render_and_store(&env.db, &env.cfg, &c).unwrap(); do_approve(&env.db, "tester", c.id, &c.identity_hash, &dd, None).unwrap(); - env.exec( - "UPDATE snapshot SET recipe_hash='sha256:0000' WHERE id=?1", - ¶ms(vec![c.snapshot_id]), - ); + env.exec("UPDATE snapshot SET recipe_hash='sha256:0000' WHERE id=?1", ¶ms(vec![c.snapshot_id])); let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap(); match pipeline::run(&env.cfg, &env.db, &id).unwrap() { pipeline::Outcome::Failed { step, error, .. } => { @@ -249,10 +219,7 @@ fn i6_manual_rebuild_publishes_the_same_version_without_a_new_approval() { full_run(&env, "plain-make"); let approvals = count(&env, "SELECT count(*) FROM approval"); let id = pipeline::enqueue_manual_rebuild(&env.cfg, &env.db, "plain-make").unwrap(); - assert!(matches!( - pipeline::run(&env.cfg, &env.db, &id).unwrap(), - pipeline::Outcome::Succeeded { .. } - )); + assert!(matches!(pipeline::run(&env.cfg, &env.db, &id).unwrap(), pipeline::Outcome::Succeeded { .. })); assert_eq!(count(&env, "SELECT count(*) FROM approval"), approvals, "a rebuild demanded a new approval"); assert_eq!( query_pairs(&env, "SELECT name, version FROM package WHERE state='in_index'"), @@ -264,18 +231,12 @@ fn i6_manual_rebuild_publishes_the_same_version_without_a_new_approval() { fn a_manual_rebuild_is_deterministic_and_its_own_build() { let (env, _fx) = env_with_fixture("plain-make"); full_run(&env, "plain-make"); - let original = env - .query_str("SELECT id FROM build ORDER BY rowid LIMIT 1", &[]) - .expect("the published build"); + let original = env.query_str("SELECT id FROM build ORDER BY rowid LIMIT 1", &[]).expect("the published build"); let a = pipeline::enqueue_manual_rebuild(&env.cfg, &env.db, "plain-make").unwrap(); let b = pipeline::enqueue_manual_rebuild(&env.cfg, &env.db, "plain-make").unwrap(); assert_eq!(a, b, "clicking rebuild twice is one build, not two"); assert_ne!(a, original, "a rebuild is a distinct build from the one that landed"); - assert_eq!( - count(&env, "SELECT count(*) FROM build"), - 2, - "the second call must not enqueue a third row" - ); + assert_eq!(count(&env, "SELECT count(*) FROM build"), 2, "the second call must not enqueue a third row"); } #[test] @@ -305,7 +266,7 @@ fn i10_audit_is_append_only_and_records_the_decisions() { .read(|c| { let mut st = c.prepare("SELECT action FROM audit")?; let rows = st.query_map([], |r| r.get::<_, String>(0))?; - Ok(rows.filter_map(|r| r.ok()).collect::<Vec<_>>()) + Ok(rows.filter_map(std::result::Result::ok).collect::<Vec<_>>()) }) .unwrap(); for want in ["approve", "publish", "build.start", "build.succeeded"] { @@ -353,10 +314,10 @@ fn index_db_names(path: &std::path::Path) -> Vec<String> { let mut names: Vec<String> = ar .entries() .unwrap() - .filter_map(|e| e.ok()) + .filter_map(std::result::Result::ok) .filter_map(|e| { let p = e.path().ok()?.to_string_lossy().into_owned(); - p.split('/').next().map(|s| s.to_string()) + p.split('/').next().map(std::string::ToString::to_string) }) .collect(); names.sort(); @@ -386,16 +347,9 @@ fn i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir() { other => panic!("a build that smuggled in a symlink must fail closed, got {other:?}"), }; assert_eq!(step, "collect", "it should be refused at collect, before anything is copied"); - assert!( - err.contains("symlink") && err.contains("staging"), - "the failure should say why it refused: {err}" - ); + assert!(err.contains("symlink") && err.contains("staging"), "the failure should say why it refused: {err}"); - assert_eq!( - dir_listing(&env.cfg.store_dir()), - store_before, - "the store must be untouched by a refused build" - ); + assert_eq!(dir_listing(&env.cfg.store_dir()), store_before, "the store must be untouched by a refused build"); assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::Failed); assert!(db::index_version(&env.db, "plain-make").unwrap().is_none(), "nothing publishes from a failed build"); assert!(secret.exists()); |
