Skip to content

Commit a7b2012

Browse files
committed
tests: Add a failing test case for OpenImageOptional with oci-archive
Prep for fixing it. Signed-off-by: Colin Walters <[email protected]>
1 parent 23efa4e commit a7b2012

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ itertools = "0.14.0"
2828
anyhow = "1.0"
2929
bytes = "1.5"
3030
clap = { version = "4.4", features = ["derive"] }
31+
tempfile = "3.20.0"
3132

3233
[lib]
3334
path = "src/imageproxy.rs"

src/imageproxy.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,19 @@ mod tests {
773773
use cap_std_ext::cap_std::fs::Dir;
774774
use rustix::fs::{memfd_create, MemfdFlags};
775775

776+
/// Check if we have skopeo
777+
fn check_skopeo() -> bool {
778+
static HAVE_SKOPEO: OnceLock<bool> = OnceLock::new();
779+
*HAVE_SKOPEO.get_or_init(|| {
780+
Command::new("skopeo")
781+
.arg("--help")
782+
.stdout(Stdio::null())
783+
.stderr(Stdio::null())
784+
.status()
785+
.is_ok()
786+
})
787+
}
788+
776789
fn validate(c: Command, contains: &[&str], not_contains: &[&str]) {
777790
// Format via debug, because
778791
// https://doc.rust-lang.org/std/process/struct.Command.html#method.get_args
@@ -1011,4 +1024,21 @@ mod tests {
10111024
Err(other) => unreachable!("{other}"),
10121025
}
10131026
}
1027+
1028+
#[tokio::test]
1029+
#[ignore = "https://github.com/coreos/rpm-ostree/issues/5442"]
1030+
async fn test_open_optional() -> Result<()> {
1031+
if !check_skopeo() {
1032+
return Ok(());
1033+
}
1034+
1035+
let td = tempfile::tempdir()?;
1036+
let td = td.path().to_str().unwrap();
1037+
let proxy = ImageProxy::new().await?;
1038+
let imgpath = format!("oci-archive:{td}/some-nonexistent-image.ociarchive");
1039+
let img = proxy.open_image_optional(&imgpath).await.unwrap();
1040+
assert!(img.is_none());
1041+
1042+
Ok(())
1043+
}
10141044
}

0 commit comments

Comments
 (0)