summaryrefslogtreecommitdiffstats
path: root/tests/common/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/common/mod.rs')
-rw-r--r--tests/common/mod.rs53
1 files changed, 23 insertions, 30 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 426f44d..b1a50ac 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -1,6 +1,3 @@
-//! Shared test scaffolding: an isolated server root in a tempdir with a migrated
-//! database and a running writer actor.
-
#![allow(dead_code)]
use std::path::{Path, PathBuf};
@@ -78,8 +75,7 @@ impl Env {
}
/// Stand in for the build+publish path: turn an approved candidate into a
- /// published release and move the accepted pointer. The real path lives in
- /// `pipeline`; detection tests need an accepted base without a build.
+ /// published release and move the accepted pointer.
pub fn accept_as_release(&self, candidate_id: i64) -> i64 {
let at = "2026-01-01T00:00:00Z";
self.db
@@ -227,9 +223,9 @@ pub fn shim_dir() -> PathBuf {
.to_path_buf()
}
-/// An environment wired to one corpus fixture: the fixture is committed into a
-/// real git repo standing in for AUR, an optional local upstream git repo exists
-/// for VCS sources, and the shims are told to obey the fixture manifest.
+/// An environment wired to one corpus fixture: the fixture is committed into a real
+/// git repo standing in for AUR, an optional local upstream git repo exists for VCS
+/// sources, and the shims obey the fixture manifest.
pub fn env_with_fixture(name: &str) -> (Env, Fixture) {
let tmp = tempfile::tempdir().expect("tempdir");
let fx = materialize_fixture(tmp.path(), name);
@@ -252,8 +248,7 @@ pub fn env_with_fixture(name: &str) -> (Env, Fixture) {
}
/// Two fixtures sharing one server root, so a test can talk about packages that
-/// depend on each other. The second fixture's manifest wins for the shim, which
-/// is what you want when the second one is the dependent.
+/// depend on each other.
pub fn env_with_two_fixtures(a: &str, b: &str) -> (Env, Fixture, Fixture) {
let tmp = tempfile::tempdir().expect("tempdir");
let fa = materialize_fixture(tmp.path(), a);
@@ -277,17 +272,17 @@ pub fn env_with_two_fixtures(a: &str, b: &str) -> (Env, Fixture, Fixture) {
(env, fa, fb)
}
-/// Copy a corpus fixture into a server root: recipe files into a git repo that
-/// stands in for AUR, payload files beside it so their bytes can be swapped,
-/// and a local upstream repo when the recipe references one.
+/// Copy a corpus fixture into a server root: recipe files into a git repo standing
+/// in for AUR, payload files beside it so their bytes can be swapped, and a local
+/// upstream repo when the recipe references one.
pub fn materialize_fixture(root: &Path, name: &str) -> Fixture {
let src = corpus_root().join(name);
assert!(src.exists(), "no fixture {name} in {}", corpus_root().display());
let manifest = root.join("manifest.json");
std::fs::copy(src.join("manifest.json"), &manifest).expect("copy manifest");
- // Data files that a source URL points at live outside the recipe so a test
- // can swap their bytes (the digest-drift case) without touching git.
+ // Data files a source URL points at live outside the recipe so a test can swap
+ // their bytes (the digest-drift case) without touching git.
let data = root.join(format!("fixture/{name}"));
std::fs::create_dir_all(&data).unwrap();
let aur = root.join(format!("aur/{name}.git"));
@@ -473,8 +468,8 @@ pub fn git(dir: &Path, args: &[&str]) -> String {
// ------------------------------------------------------------- web driver --
-/// A tiny HTTP client for the surface tests: keeps the session cookie and the
-/// CSRF token, and hands back status + body.
+/// A tiny HTTP client for the surface tests: keeps the session cookie and the CSRF
+/// token, and hands back status + body.
pub struct Web {
pub env: Env,
pub fx: Fixture,
@@ -526,8 +521,8 @@ impl Web {
aur_build::review::candidates::candidate_by_id(&self.env.db, c.id).unwrap().unwrap()
}
- /// Approve through the library and run the build to publication, so a test
- /// can talk about "what the index serves" without re-implementing P0.
+ /// Approve through the library and run the build to publication, so a test can
+ /// talk about "what the index serves".
pub fn publish(&self, name: &str) {
let c = self.open_review(name);
aur_build::review::approve::approve(&self.env.db, "test", c.id, &c.identity_hash, &c.diff_digest, None)
@@ -550,8 +545,8 @@ impl Web {
};
let cookie = r.header("set-cookie").map(|s| s.to_string()).unwrap_or_default();
let mut headers = vec![("set-cookie".to_string(), cookie)];
- // ureq 2 will not hand out the whole header map, but it will answer for a
- // named one, which is all the assertions below need.
+ // ureq 2 will not hand out the whole header map, but it answers for a named
+ // one, which is all the assertions below need.
for name in ["content-type", "content-encoding", "location"] {
if let Some(v) = r.header(name) {
headers.push((name.to_string(), v.to_string()));
@@ -577,10 +572,9 @@ impl Web {
self.finish(resp, path)
}
- /// Send a request over a bare socket: no cookie jar, no redirect following,
- /// so the test sees the 303 a browser would have swallowed. The session
- /// gate is only meaningful at this level — a client that follows redirects
- /// turns "you are not signed in" into the login page's 200.
+ /// Send a request over a bare socket: no cookie jar, no redirect following, so
+ /// the test sees the 303 a browser would have swallowed. The session gate is
+ /// only meaningful at this level.
pub fn raw_request(&self, method: &str, path: &str, headers: &[(&str, String)], body: Option<&str>) -> Raw {
use std::io::{Read, Write};
let addr = self.server.addr.clone();
@@ -604,9 +598,8 @@ impl Web {
Raw::parse(&raw)
}
- /// Log in and adopt the session cookie the server issued, refreshing the
- /// CSRF token with it — the token is derived from the sid, so a login that
- /// rotates the session invalidates the one captured before it.
+ /// Log in and adopt the session cookie the server issued, refreshing the CSRF
+ /// token with it — the token is derived from the sid.
pub fn login(&mut self, password: &str) -> Raw {
let raw = self.raw_request("POST", "/login", &[], Some(&format!("password={}", url_encode(password))));
if let Some(cookie) = raw.cookie() {
@@ -673,8 +666,8 @@ fn url_encode(s: &str) -> String {
.collect()
}
-/// Pull an attribute or meta value out of rendered HTML and undo the escaping
-/// the templates applied — a page is the contract here, so we read it as one.
+/// Pull an attribute or meta value out of rendered HTML and undo the escaping the
+/// templates applied — a page is the contract here, so we read it as one.
pub fn extract(hay: &str, open: &str, close: &str) -> Option<String> {
let i = hay.find(open)? + open.len();
let rest = &hay[i..];