Skip to content

Commit 86a06ec

Browse files
authored
Merge pull request #1003 from cgwalters/no-skopeo-unit
tests: Handle not having skopeo present
2 parents a408792 + a3427e4 commit 86a06ec

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ exclude-crate-paths = [ { name = "libz-sys", exclude = "src/zlib" },
7070
{ name = "k8s-openapi", exclude = "src/v1_27" },
7171
]
7272

73+
# This is an made up key for external binary dependencies.
74+
# setpriv is a proxy for util-linux, and systemctl is a proxy for systemd.
75+
[workspace.metadata.binary-dependencies]
76+
bins = ["skopeo", "podman", "ostree", "zstd", "setpriv", "systemctl"]
77+
7378
[workspace.lints.rust]
7479
# Require an extra opt-in for unsafe
7580
unsafe_code = "deny"

ci/installdeps.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ enabled=1
2424
enabled_metadata=1
2525
EOF
2626

27-
# Our tests depend on this
28-
dnf -y install skopeo zstd
29-
27+
# TODO: Recursively extract this from the existing cargo system-deps metadata
3028
case $OS_ID in
3129
fedora) dnf -y builddep bootc ;;
3230
*) dnf -y install libzstd-devel openssl-devel ostree-devel cargo ;;
3331
esac
32+
33+
bindeps=$(cargo metadata --format-version 1 --no-deps | jq -r '.metadata.["binary-dependencies"].bins | map("/usr/bin/" + .) | join(" ")')
34+
dnf -y install $bindeps

ostree-ext/tests/it/main.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use containers_image_proxy::oci_spec;
88
use oci_image::ImageManifest;
99
use oci_spec::image as oci_image;
1010
use ocidir::oci_spec::image::{Arch, DigestAlgorithm};
11-
use once_cell::sync::Lazy;
11+
use once_cell::sync::{Lazy, OnceCell};
1212
use ostree_ext::chunking::ObjectMetaSized;
1313
use ostree_ext::container::{store, ManifestDiff};
1414
use ostree_ext::container::{
@@ -32,6 +32,12 @@ use ostree_ext::fixture::{
3232
const EXAMPLE_TAR_LAYER: &[u8] = include_bytes!("fixtures/hlinks.tar.gz");
3333
const TEST_REGISTRY_DEFAULT: &str = "localhost:5000";
3434

35+
/// Check if we have skopeo
36+
fn check_skopeo() -> bool {
37+
static HAVE_SKOPEO: OnceCell<bool> = OnceCell::new();
38+
*HAVE_SKOPEO.get_or_init(|| Command::new("skopeo").arg("--help").status().is_ok())
39+
}
40+
3541
#[track_caller]
3642
fn assert_err_contains<T>(r: Result<T>, s: impl AsRef<str>) {
3743
let s = s.as_ref();
@@ -624,6 +630,9 @@ async fn impl_test_container_import_export(chunked: bool) -> Result<()> {
624630

625631
#[tokio::test]
626632
async fn test_export_as_container_nonderived() -> Result<()> {
633+
if !check_skopeo() {
634+
return Ok(());
635+
}
627636
let fixture = Fixture::new_v1()?;
628637
// Export into an OCI directory
629638
let src_imgref = fixture.export_container().await.unwrap().0;
@@ -662,6 +671,9 @@ async fn test_export_as_container_nonderived() -> Result<()> {
662671

663672
#[tokio::test]
664673
async fn test_export_as_container_derived() -> Result<()> {
674+
if !check_skopeo() {
675+
return Ok(());
676+
}
665677
let fixture = Fixture::new_v1()?;
666678
// Export into an OCI directory
667679
let src_imgref = fixture.export_container().await.unwrap().0;
@@ -711,6 +723,9 @@ async fn test_export_as_container_derived() -> Result<()> {
711723

712724
#[tokio::test]
713725
async fn test_unencapsulate_unbootable() -> Result<()> {
726+
if !check_skopeo() {
727+
return Ok(());
728+
}
714729
let fixture = {
715730
let mut fixture = Fixture::new_base()?;
716731
fixture.bootable = false;
@@ -801,6 +816,9 @@ fn validate_chunked_structure(oci_path: &Utf8Path) -> Result<()> {
801816

802817
#[tokio::test]
803818
async fn test_container_arch_mismatch() -> Result<()> {
819+
if !check_skopeo() {
820+
return Ok(());
821+
}
804822
let fixture = Fixture::new_v1()?;
805823

806824
let imgref = fixture.export_container().await.unwrap().0;
@@ -850,6 +868,9 @@ async fn test_container_arch_mismatch() -> Result<()> {
850868

851869
#[tokio::test]
852870
async fn test_container_chunked() -> Result<()> {
871+
if !check_skopeo() {
872+
return Ok(());
873+
}
853874
let nlayers = LAYERS_V0_LEN - 1;
854875
let mut fixture = Fixture::new_v1()?;
855876

@@ -1044,6 +1065,9 @@ r usr/bin/bash bash-v0
10441065

10451066
#[tokio::test]
10461067
async fn test_container_var_content() -> Result<()> {
1068+
if !check_skopeo() {
1069+
return Ok(());
1070+
}
10471071
let fixture = Fixture::new_v1()?;
10481072

10491073
let imgref = fixture.export_container().await.unwrap().0;
@@ -1146,6 +1170,9 @@ async fn test_container_etc_hardlinked_relative() -> Result<()> {
11461170
}
11471171

11481172
async fn test_container_etc_hardlinked(absolute: bool) -> Result<()> {
1173+
if !check_skopeo() {
1174+
return Ok(());
1175+
}
11491176
let fixture = Fixture::new_v1()?;
11501177

11511178
let imgref = fixture.export_container().await.unwrap().0;
@@ -1257,6 +1284,9 @@ async fn test_container_etc_hardlinked(absolute: bool) -> Result<()> {
12571284

12581285
#[tokio::test]
12591286
async fn test_non_ostree() -> Result<()> {
1287+
if !check_skopeo() {
1288+
return Ok(());
1289+
}
12601290
let fixture = NonOstreeFixture::new_base()?;
12611291
let src_digest = fixture.export_container().await?.1;
12621292

@@ -1285,13 +1315,19 @@ async fn oci_clone(src: impl AsRef<Utf8Path>, dest: impl AsRef<Utf8Path>) -> Res
12851315

12861316
#[tokio::test]
12871317
async fn test_container_import_export_v1() {
1318+
if !check_skopeo() {
1319+
return;
1320+
}
12881321
impl_test_container_import_export(false).await.unwrap();
12891322
impl_test_container_import_export(true).await.unwrap();
12901323
}
12911324

12921325
/// But layers work via the container::write module.
12931326
#[tokio::test]
12941327
async fn test_container_write_derive() -> Result<()> {
1328+
if !check_skopeo() {
1329+
return Ok(());
1330+
}
12951331
let cancellable = gio::Cancellable::NONE;
12961332
let fixture = Fixture::new_v1()?;
12971333
let sh = fixture.new_shell()?;
@@ -1539,6 +1575,9 @@ async fn test_container_write_derive() -> Result<()> {
15391575

15401576
/// Implementation of a test case for non-gzip (i.e. zstd or zstd:chunked) compression
15411577
async fn test_non_gzip(format: &str) -> Result<()> {
1578+
if !check_skopeo() {
1579+
return Ok(());
1580+
}
15421581
let fixture = Fixture::new_v1()?;
15431582
let baseimg = &fixture.export_container().await?.0;
15441583
let basepath = &match baseimg.transport {
@@ -1592,6 +1631,9 @@ async fn test_container_zstd_chunked() -> Result<()> {
15921631
/// We need to handle the case of modified hardlinks into /sysroot
15931632
#[tokio::test]
15941633
async fn test_container_write_derive_sysroot_hardlink() -> Result<()> {
1634+
if !check_skopeo() {
1635+
return Ok(());
1636+
}
15951637
let fixture = Fixture::new_v1()?;
15961638
let sh = fixture.new_shell()?;
15971639
let baseimg = &fixture.export_container().await?.0;
@@ -1688,6 +1730,9 @@ async fn test_container_write_derive_sysroot_hardlink() -> Result<()> {
16881730
// verifies that the old ostree-rs-ext code can parse the containers
16891731
// generated by the new ostree code.
16901732
async fn test_old_code_parses_new_export() -> Result<()> {
1733+
if !check_skopeo() {
1734+
return Ok(());
1735+
}
16911736
let rpmostree = Utf8Path::new("/usr/bin/rpm-ostree");
16921737
if !rpmostree.exists() {
16931738
return Ok(());
@@ -1722,6 +1767,9 @@ async fn test_old_code_parses_new_export() -> Result<()> {
17221767
/// Test for https://github.com/ostreedev/ostree-rs-ext/issues/655
17231768
#[tokio::test]
17241769
async fn test_container_xattr() -> Result<()> {
1770+
if !check_skopeo() {
1771+
return Ok(());
1772+
}
17251773
let fixture = Fixture::new_v1()?;
17261774
let sh = fixture.new_shell()?;
17271775
let baseimg = &fixture.export_container().await?.0;

0 commit comments

Comments
 (0)