From a7b2012dd86df84c44b17a70b60bc2b3ed0f2b6e Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 30 Jul 2025 11:48:06 -0400 Subject: [PATCH] tests: Add a failing test case for OpenImageOptional with oci-archive Prep for fixing it. Signed-off-by: Colin Walters --- Cargo.toml | 1 + src/imageproxy.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 3ad1eb5..2cd6d84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ itertools = "0.14.0" anyhow = "1.0" bytes = "1.5" clap = { version = "4.4", features = ["derive"] } +tempfile = "3.20.0" [lib] path = "src/imageproxy.rs" diff --git a/src/imageproxy.rs b/src/imageproxy.rs index d3fe99e..4638582 100644 --- a/src/imageproxy.rs +++ b/src/imageproxy.rs @@ -773,6 +773,19 @@ mod tests { use cap_std_ext::cap_std::fs::Dir; use rustix::fs::{memfd_create, MemfdFlags}; + /// Check if we have skopeo + fn check_skopeo() -> bool { + static HAVE_SKOPEO: OnceLock = OnceLock::new(); + *HAVE_SKOPEO.get_or_init(|| { + Command::new("skopeo") + .arg("--help") + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .is_ok() + }) + } + fn validate(c: Command, contains: &[&str], not_contains: &[&str]) { // Format via debug, because // https://doc.rust-lang.org/std/process/struct.Command.html#method.get_args @@ -1011,4 +1024,21 @@ mod tests { Err(other) => unreachable!("{other}"), } } + + #[tokio::test] + #[ignore = "https://github.com/coreos/rpm-ostree/issues/5442"] + async fn test_open_optional() -> Result<()> { + if !check_skopeo() { + return Ok(()); + } + + let td = tempfile::tempdir()?; + let td = td.path().to_str().unwrap(); + let proxy = ImageProxy::new().await?; + let imgpath = format!("oci-archive:{td}/some-nonexistent-image.ociarchive"); + let img = proxy.open_image_optional(&imgpath).await.unwrap(); + assert!(img.is_none()); + + Ok(()) + } }