diff options
Diffstat (limited to 'tests/common')
| -rw-r--r-- | tests/common/mod.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 0dc5396..d2582c9 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -245,10 +245,13 @@ pub fn materialize_fixture(root: &Path, name: &str) -> Fixture { std::fs::create_dir_all(&aur).unwrap(); let upstream = root.join(format!("upstream/{name}")); + let upstream2 = root.join(format!("upstream/{name}-2")); let subs = [ ("@AUR_DIR@".to_string(), data.display().to_string()), ("@UPSTREAM_DIR@".to_string(), upstream.display().to_string()), + ("@UPSTREAM2_DIR@".to_string(), upstream2.display().to_string()), ]; + let mut has_upstream2 = false; let mut recipe_files: Vec<(String, String)> = Vec::new(); let mut has_upstream_ref = false; @@ -261,6 +264,7 @@ pub fn materialize_fixture(root: &Path, name: &str) -> Fixture { let body = std::fs::read_to_string(&path).unwrap_or_default(); let body = subs.iter().fold(body, |b, (from, to)| b.replace(from, to)); has_upstream_ref |= body.contains(&upstream.display().to_string()); + has_upstream2 |= body.contains(&upstream2.display().to_string()); if matches!(fname.as_str(), "payload.bin" | "data.bin") { std::fs::write(data.join(&fname), &body).unwrap(); } else { @@ -270,6 +274,16 @@ pub fn materialize_fixture(root: &Path, name: &str) -> Fixture { if has_upstream_ref { make_git_repo(&upstream, &[("README", "upstream\n")], "upstream: initial"); } + if has_upstream2 { + make_git_repo(&upstream2, &[("README", "second upstream\n")], "upstream: initial"); + } + // A `#tag=v1` source needs the tag to exist. + if std::fs::read_to_string(src.join("PKGBUILD")) + .unwrap_or_default() + .contains("#tag=") + { + git(&upstream, &["tag", "v1"]); + } make_git_repo( &aur, &recipe_files.iter().map(|(n, b)| (n.as_str(), b.as_str())).collect::<Vec<_>>(), @@ -282,6 +296,7 @@ pub fn materialize_fixture(root: &Path, name: &str) -> Fixture { data, manifest, upstream: has_upstream_ref.then_some(upstream), + upstream2: has_upstream2.then_some(upstream2), } } @@ -292,6 +307,8 @@ pub struct Fixture { pub data: PathBuf, pub manifest: PathBuf, pub upstream: Option<PathBuf>, + /// A second upstream repo, for pkgbases that build from two of them. + pub upstream2: Option<PathBuf>, } impl Fixture { @@ -333,6 +350,24 @@ impl Fixture { git(&up, &["rev-parse", "HEAD"]) } + /// Add a commit to the second upstream repo. + pub fn upstream2_commit(&self, body: &str) -> String { + let up = self.upstream2.clone().expect("fixture has no second upstream repo"); + git_add_commit(&up, &[(("README"), body)], body); + git(&up, &["rev-parse", "HEAD"]) + } + + /// HEAD of the (first) upstream repo. + pub fn upstream_head(&self) -> String { + let up = self.upstream.clone().expect("fixture has no upstream repo"); + git(&up, &["rev-parse", "HEAD"]) + } + + pub fn upstream2_head(&self) -> String { + let up = self.upstream2.clone().expect("fixture has no second upstream repo"); + git(&up, &["rev-parse", "HEAD"]) + } + pub fn manifest_json(&self) -> serde_json::Value { serde_json::from_str(&std::fs::read_to_string(&self.manifest).unwrap()).unwrap() } |
