@@ -8,7 +8,7 @@ use containers_image_proxy::oci_spec;
88use oci_image:: ImageManifest ;
99use oci_spec:: image as oci_image;
1010use ocidir:: oci_spec:: image:: { Arch , DigestAlgorithm } ;
11- use once_cell:: sync:: Lazy ;
11+ use once_cell:: sync:: { Lazy , OnceCell } ;
1212use ostree_ext:: chunking:: ObjectMetaSized ;
1313use ostree_ext:: container:: { store, ManifestDiff } ;
1414use ostree_ext:: container:: {
@@ -32,6 +32,12 @@ use ostree_ext::fixture::{
3232const EXAMPLE_TAR_LAYER : & [ u8 ] = include_bytes ! ( "fixtures/hlinks.tar.gz" ) ;
3333const 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]
3642fn 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]
626632async 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]
664673async 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]
713725async 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]
803818async 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]
852870async 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]
10461067async 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
11481172async 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]
12591286async 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]
12871317async 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]
12941327async 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
15411577async 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]
15941633async 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.
16901732async 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]
17241769async 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