diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/approve.rs | 5 | ||||
| -rw-r--r-- | tests/architecture-budget.json | 38 | ||||
| -rw-r--r-- | tests/common/mod.rs | 17 | ||||
| -rw-r--r-- | tests/detect.rs | 45 |
4 files changed, 41 insertions, 64 deletions
diff --git a/tests/approve.rs b/tests/approve.rs index 7d014f8..c5be8e0 100644 --- a/tests/approve.rs +++ b/tests/approve.rs @@ -108,7 +108,10 @@ fn a_broken_database_is_not_reported_as_a_stale_review() { fn bulk_refusals_are_their_own_reasons() { let (env, _fx) = env_with_fixture("plain-make"); let (c, dd) = open_review(&env, "plain-make"); - candidates::set_risk_for_tests(&env.db, c.id, "high", &["new source host".into()]).unwrap(); + env.execute( + "UPDATE candidate SET risk_level=?1, risk_signals_json=?2 WHERE id=?3", + &[P::S("high".into()), P::S(r#"["new source host"]"#.into()), P::I(c.id)], + ); let items = [(c.id, c.identity_hash.clone(), dd.clone())]; let out = bulk(&env.db, "tester", &items, "approve", &[]).unwrap(); diff --git a/tests/architecture-budget.json b/tests/architecture-budget.json index 422bfb5..4df78b1 100644 --- a/tests/architecture-budget.json +++ b/tests/architecture-budget.json @@ -232,15 +232,15 @@ "test": 0 }, "review": { - "dead": 10, - "deadonly": 5, + "dead": 5, + "deadonly": 1, "glob": 0, - "largest": 295, + "largest": 288, "largest_file": "src/review/diff.rs", - "lines": 880, - "priv": 2, - "pub": 29, - "test": 5 + "lines": 859, + "priv": 3, + "pub": 24, + "test": 4 }, "sandbox": { "dead": 15, @@ -298,27 +298,27 @@ "test": 0 }, "watch": { - "dead": 13, - "deadonly": 7, + "dead": 8, + "deadonly": 4, "glob": 0, "largest": 270, "largest_file": "src/watch/detect.rs", - "lines": 970, - "priv": 2, - "pub": 30, - "test": 6 + "lines": 1038, + "priv": 7, + "pub": 24, + "test": 4 } }, "totals": { - "dead": 115, - "deadonly": 40, + "dead": 105, + "deadonly": 33, "edges": 87, "glob": 0, "largest": 603, "largest_file": "src/shims/mod.rs", - "lines": 14244, - "priv": 103, - "pub": 516, - "test": 75 + "lines": 14291, + "priv": 109, + "pub": 505, + "test": 72 } } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index d1c07a4..5c48923 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -128,6 +128,23 @@ impl Env { self.cfg.hooks.shim_fail = Some(tool.to_string()); } + /// Run a statement the library deliberately does not expose. + /// + /// Fixtures use this to put a row in a state production would take a long + /// way to reach — forcing a risk level, say — rather than the library + /// growing a public setter that exists only for tests. + pub fn execute(&self, sql: &str, params: &[P]) { + let c = rusqlite::Connection::open(self.cfg.db_path()).unwrap(); + let refs: Vec<&dyn rusqlite::ToSql> = params + .iter() + .map(|p| match p { + P::I(i) => i as &dyn rusqlite::ToSql, + P::S(s) => s as &dyn rusqlite::ToSql, + }) + .collect(); + c.execute(sql, rusqlite::params_from_iter(refs)).unwrap(); + } + pub fn query_i64(&self, sql: &str, params: &[P]) -> Option<i64> { let sql = sql.to_string(); let params: Vec<P> = params.to_vec(); diff --git a/tests/detect.rs b/tests/detect.rs index ef57121..86d1315 100644 --- a/tests/detect.rs +++ b/tests/detect.rs @@ -5,7 +5,7 @@ use common::{git_add_commit, make_git_repo, params, Env, P}; use aur_build::db::{self, model::*, ReleaseRow}; use aur_build::review::{approve, candidates}; use aur_build::watch::detect::{check_pkgbase, Outcome}; -use aur_build::watch::mirror::{read_tree, sync_mirror, Sync}; +use aur_build::watch::mirror::{sync_mirror, Sync}; fn aur(env: &Env, name: &str) -> std::path::PathBuf { env.path(&format!("aur/{name}.git")) @@ -403,46 +403,3 @@ fn notices_are_not_duplicated_by_repeated_polling() { ); let _ = P::I(0); } - -#[test] -fn read_tree_returns_every_blob_from_one_batch_read() { - let env = Env::new(); - env.subscribe("foo"); - make_git_repo( - &aur(&env, "foo"), - &[ - ("PKGBUILD", &common::pkgbuild("foo", "1.0", "1", "")), - ("empty.txt", ""), - ("blob.bin", "\u{0}not text"), - ], - "initial", - ); - let url = format!("file://{}", aur(&env, "foo").display()); - sync_mirror(&env.cfg, &env.db, "foo", &url).unwrap(); - let mirror = env.cfg.mirror_path("foo"); - let head = aur_build::git::head(&mirror).unwrap(); - let tree = read_tree(&mirror, &head).unwrap(); - - assert!(tree.files["PKGBUILD"].contains("pkgver=1.0")); - assert_eq!(tree.files["empty.txt"], "", "an empty blob is a file, not a miss"); - assert!( - !tree.files.contains_key("blob.bin"), - "a NUL in the first block means it is not text: {:?}", - tree.files.keys().collect::<Vec<_>>() - ); -} - -#[test] -fn read_tree_fails_closed_when_the_commit_is_gone_from_the_mirror() { - let env = Env::new(); - env.subscribe("foo"); - seed(&env, "foo", "1.0", "1", ""); - let url = format!("file://{}", aur(&env, "foo").display()); - sync_mirror(&env.cfg, &env.db, "foo", &url).unwrap(); - let mirror = env.cfg.mirror_path("foo"); - - for gone in ["0123456789012345678901234567890123456789", "deadbeef"] { - let err = read_tree(&mirror, gone).unwrap_err().to_string(); - assert!(err.contains("missing from the local mirror"), "{gone}: {err}"); - } -} |
