From 1e023b22cedaec6ed8aaaa8832d0a07fa22de993 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 1 Jun 2024 15:14:07 -0400 Subject: [PATCH] tests: Add some error context This helped me debug a recent problem. --- lib/src/fixture.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/src/fixture.rs b/lib/src/fixture.rs index bae068c7..35f406d8 100644 --- a/lib/src/fixture.rs +++ b/lib/src/fixture.rs @@ -254,8 +254,10 @@ pub fn create_dirmeta(path: &Utf8Path, selinux: bool) -> glib::Variant { } /// Wraps [`create_dirmeta`] and commits it. +#[context("Init dirmeta for {path}")] pub fn require_dirmeta(repo: &ostree::Repo, path: &Utf8Path, selinux: bool) -> Result { let v = create_dirmeta(path, selinux); + ostree::validate_structureof_dirmeta(&v).context("Validating dirmeta")?; let r = repo.write_metadata( ostree::ObjectType::DirMeta, None, @@ -454,6 +456,7 @@ impl Fixture { Ok(()) } + #[context("Writing filedef {}", def.path.as_str())] pub fn write_filedef(&self, root: &ostree::MutableTree, def: &FileDef) -> Result<()> { let parent_path = def.path.parent(); let parent = if let Some(parent_path) = parent_path { @@ -472,15 +475,18 @@ impl Fixture { let xattrs = label.map(|v| v.new_xattrs()); let xattrs = xattrs.as_ref(); let checksum = match &def.ty { - FileDefType::Regular(contents) => self.srcrepo.write_regfile_inline( - None, - 0, - 0, - libc::S_IFREG | def.mode, - xattrs, - contents.as_bytes(), - gio::Cancellable::NONE, - )?, + FileDefType::Regular(contents) => self + .srcrepo + .write_regfile_inline( + None, + 0, + 0, + libc::S_IFREG | def.mode, + xattrs, + contents.as_bytes(), + gio::Cancellable::NONE, + ) + .context("Writing regfile inline")?, FileDefType::Symlink(target) => self.srcrepo.write_symlink( None, def.uid, @@ -496,7 +502,9 @@ impl Fixture { return Ok(()); } }; - parent.replace_file(name, checksum.as_str())?; + parent + .replace_file(name, checksum.as_str()) + .context("Setting file")?; Ok(()) }