Skip to content

tests: Add a failing test case for OpenImageOptional with oci-archive #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
30 changes: 30 additions & 0 deletions src/imageproxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> = 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
Expand Down Expand Up @@ -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(())
}
}
Loading