Skip to content

Commit

Permalink
Merge pull request #1003 from cgwalters/no-skopeo-unit
Browse files Browse the repository at this point in the history
tests: Handle not having skopeo present
  • Loading branch information
cgwalters authored Jan 6, 2025
2 parents a408792 + a3427e4 commit 86a06ec
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ exclude-crate-paths = [ { name = "libz-sys", exclude = "src/zlib" },
{ name = "k8s-openapi", exclude = "src/v1_27" },
]

# This is an made up key for external binary dependencies.
# setpriv is a proxy for util-linux, and systemctl is a proxy for systemd.
[workspace.metadata.binary-dependencies]
bins = ["skopeo", "podman", "ostree", "zstd", "setpriv", "systemctl"]

[workspace.lints.rust]
# Require an extra opt-in for unsafe
unsafe_code = "deny"
Expand Down
7 changes: 4 additions & 3 deletions ci/installdeps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ enabled=1
enabled_metadata=1
EOF

# Our tests depend on this
dnf -y install skopeo zstd

# TODO: Recursively extract this from the existing cargo system-deps metadata
case $OS_ID in
fedora) dnf -y builddep bootc ;;
*) dnf -y install libzstd-devel openssl-devel ostree-devel cargo ;;
esac

bindeps=$(cargo metadata --format-version 1 --no-deps | jq -r '.metadata.["binary-dependencies"].bins | map("/usr/bin/" + .) | join(" ")')
dnf -y install $bindeps
50 changes: 49 additions & 1 deletion ostree-ext/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use containers_image_proxy::oci_spec;
use oci_image::ImageManifest;
use oci_spec::image as oci_image;
use ocidir::oci_spec::image::{Arch, DigestAlgorithm};
use once_cell::sync::Lazy;
use once_cell::sync::{Lazy, OnceCell};
use ostree_ext::chunking::ObjectMetaSized;
use ostree_ext::container::{store, ManifestDiff};
use ostree_ext::container::{
Expand All @@ -32,6 +32,12 @@ use ostree_ext::fixture::{
const EXAMPLE_TAR_LAYER: &[u8] = include_bytes!("fixtures/hlinks.tar.gz");
const TEST_REGISTRY_DEFAULT: &str = "localhost:5000";

/// Check if we have skopeo
fn check_skopeo() -> bool {
static HAVE_SKOPEO: OnceCell<bool> = OnceCell::new();
*HAVE_SKOPEO.get_or_init(|| Command::new("skopeo").arg("--help").status().is_ok())
}

#[track_caller]
fn assert_err_contains<T>(r: Result<T>, s: impl AsRef<str>) {
let s = s.as_ref();
Expand Down Expand Up @@ -624,6 +630,9 @@ async fn impl_test_container_import_export(chunked: bool) -> Result<()> {

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

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

#[tokio::test]
async fn test_unencapsulate_unbootable() -> Result<()> {
if !check_skopeo() {
return Ok(());
}
let fixture = {
let mut fixture = Fixture::new_base()?;
fixture.bootable = false;
Expand Down Expand Up @@ -801,6 +816,9 @@ fn validate_chunked_structure(oci_path: &Utf8Path) -> Result<()> {

#[tokio::test]
async fn test_container_arch_mismatch() -> Result<()> {
if !check_skopeo() {
return Ok(());
}
let fixture = Fixture::new_v1()?;

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

#[tokio::test]
async fn test_container_chunked() -> Result<()> {
if !check_skopeo() {
return Ok(());
}
let nlayers = LAYERS_V0_LEN - 1;
let mut fixture = Fixture::new_v1()?;

Expand Down Expand Up @@ -1044,6 +1065,9 @@ r usr/bin/bash bash-v0

#[tokio::test]
async fn test_container_var_content() -> Result<()> {
if !check_skopeo() {
return Ok(());
}
let fixture = Fixture::new_v1()?;

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

async fn test_container_etc_hardlinked(absolute: bool) -> Result<()> {
if !check_skopeo() {
return Ok(());
}
let fixture = Fixture::new_v1()?;

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

#[tokio::test]
async fn test_non_ostree() -> Result<()> {
if !check_skopeo() {
return Ok(());
}
let fixture = NonOstreeFixture::new_base()?;
let src_digest = fixture.export_container().await?.1;

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

#[tokio::test]
async fn test_container_import_export_v1() {
if !check_skopeo() {
return;
}
impl_test_container_import_export(false).await.unwrap();
impl_test_container_import_export(true).await.unwrap();
}

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

/// Implementation of a test case for non-gzip (i.e. zstd or zstd:chunked) compression
async fn test_non_gzip(format: &str) -> Result<()> {
if !check_skopeo() {
return Ok(());
}
let fixture = Fixture::new_v1()?;
let baseimg = &fixture.export_container().await?.0;
let basepath = &match baseimg.transport {
Expand Down Expand Up @@ -1592,6 +1631,9 @@ async fn test_container_zstd_chunked() -> Result<()> {
/// We need to handle the case of modified hardlinks into /sysroot
#[tokio::test]
async fn test_container_write_derive_sysroot_hardlink() -> Result<()> {
if !check_skopeo() {
return Ok(());
}
let fixture = Fixture::new_v1()?;
let sh = fixture.new_shell()?;
let baseimg = &fixture.export_container().await?.0;
Expand Down Expand Up @@ -1688,6 +1730,9 @@ async fn test_container_write_derive_sysroot_hardlink() -> Result<()> {
// verifies that the old ostree-rs-ext code can parse the containers
// generated by the new ostree code.
async fn test_old_code_parses_new_export() -> Result<()> {
if !check_skopeo() {
return Ok(());
}
let rpmostree = Utf8Path::new("/usr/bin/rpm-ostree");
if !rpmostree.exists() {
return Ok(());
Expand Down Expand Up @@ -1722,6 +1767,9 @@ async fn test_old_code_parses_new_export() -> Result<()> {
/// Test for https://github.com/ostreedev/ostree-rs-ext/issues/655
#[tokio::test]
async fn test_container_xattr() -> Result<()> {
if !check_skopeo() {
return Ok(());
}
let fixture = Fixture::new_v1()?;
let sh = fixture.new_shell()?;
let baseimg = &fixture.export_container().await?.0;
Expand Down

0 comments on commit 86a06ec

Please sign in to comment.