Skip to content

Commit

Permalink
tests: Add some error context
Browse files Browse the repository at this point in the history
This helped me debug a recent problem.
  • Loading branch information
cgwalters committed Jun 1, 2024
1 parent 6c090d8 commit 1e023b2
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
let v = create_dirmeta(path, selinux);
ostree::validate_structureof_dirmeta(&v).context("Validating dirmeta")?;
let r = repo.write_metadata(
ostree::ObjectType::DirMeta,
None,
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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(())
}

Expand Down

0 comments on commit 1e023b2

Please sign in to comment.