1616
1717use camino:: Utf8PathBuf ;
1818use color_eyre:: Result ;
19- use integration_tests:: integration_test;
19+ use integration_tests:: { integration_test, parameterized_integration_test } ;
2020use linkme:: distributed_slice;
2121
2222use std:: process:: Command ;
2323use tempfile:: TempDir ;
2424
25- use crate :: { get_test_image, run_bcvk, INTEGRATION_TEST_LABEL } ;
26-
27- /// Test actual bootc installation to a disk image
28- fn test_to_disk ( ) -> Result < ( ) > {
29- let temp_dir = TempDir :: new ( ) . expect ( "Failed to create temp directory" ) ;
30- let disk_path = Utf8PathBuf :: try_from ( temp_dir. path ( ) . join ( "test-disk.img" ) )
31- . expect ( "temp path is not UTF-8" ) ;
32-
33- let output = run_bcvk ( & [
34- "to-disk" ,
35- "--label" ,
36- INTEGRATION_TEST_LABEL ,
37- & get_test_image ( ) ,
38- disk_path. as_str ( ) ,
39- ] ) ?;
40-
41- assert ! (
42- output. success( ) ,
43- "to-disk failed with exit code: {:?}. stdout: {}, stderr: {}" ,
44- output. exit_code( ) ,
45- output. stdout,
46- output. stderr
47- ) ;
48-
49- let metadata = std:: fs:: metadata ( & disk_path) . expect ( "Failed to get disk metadata" ) ;
50- assert ! ( metadata. len( ) > 0 ) ;
25+ use crate :: { get_test_image, run_bcvk, CapturedOutput , INTEGRATION_TEST_LABEL } ;
26+
27+ /// Validate that a disk image was created successfully with proper bootc installation
28+ ///
29+ /// This helper function verifies:
30+ /// - The disk image file exists and has non-zero size
31+ /// - The disk has valid partition table (using sfdisk)
32+ /// - The installation completed successfully (from output messages)
33+ fn validate_disk_image (
34+ disk_path : & Utf8PathBuf ,
35+ output : & CapturedOutput ,
36+ context : & str ,
37+ ) -> Result < ( ) > {
38+ let metadata = std:: fs:: metadata ( disk_path) . expect ( "Failed to get disk metadata" ) ;
39+ assert ! ( metadata. len( ) > 0 , "{}: Disk image is empty" , context) ;
5140
5241 // Verify the disk has partitions using sfdisk -l
5342 let sfdisk_output = Command :: new ( "sfdisk" )
@@ -60,14 +49,16 @@ fn test_to_disk() -> Result<()> {
6049
6150 assert ! (
6251 sfdisk_output. status. success( ) ,
63- "sfdisk failed with exit code: {:?}" ,
52+ "{}: sfdisk failed with exit code: {:?}" ,
53+ context,
6454 sfdisk_output. status. code( )
6555 ) ;
6656
6757 assert ! (
6858 sfdisk_stdout. contains( "Disk " )
6959 && ( sfdisk_stdout. contains( "sectors" ) || sfdisk_stdout. contains( "bytes" ) ) ,
70- "sfdisk output doesn't show expected disk information"
60+ "{}: sfdisk output doesn't show expected disk information" ,
61+ context
7162 ) ;
7263
7364 let has_partitions = sfdisk_stdout. lines ( ) . any ( |line| {
@@ -76,15 +67,43 @@ fn test_to_disk() -> Result<()> {
7667
7768 assert ! (
7869 has_partitions,
79- "No bootc partitions found in sfdisk output. Output was:\n {}" ,
80- sfdisk_stdout
70+ "{}: No bootc partitions found in sfdisk output. Output was:\n {}" ,
71+ context , sfdisk_stdout
8172 ) ;
8273
8374 assert ! (
8475 output. stdout. contains( "Installation complete" ) || output. stderr. contains( "Installation complete" ) ,
85- "No 'Installation complete' message found in output. This indicates bootc install did not complete successfully. stdout: {}, stderr: {}" ,
76+ "{}: No 'Installation complete' message found in output. This indicates bootc install did not complete successfully. stdout: {}, stderr: {}" ,
77+ context,
8678 output. stdout, output. stderr
8779 ) ;
80+
81+ Ok ( ( ) )
82+ }
83+
84+ /// Test actual bootc installation to a disk image
85+ fn test_to_disk ( ) -> Result < ( ) > {
86+ let temp_dir = TempDir :: new ( ) . expect ( "Failed to create temp directory" ) ;
87+ let disk_path = Utf8PathBuf :: try_from ( temp_dir. path ( ) . join ( "test-disk.img" ) )
88+ . expect ( "temp path is not UTF-8" ) ;
89+
90+ let output = run_bcvk ( & [
91+ "to-disk" ,
92+ "--label" ,
93+ INTEGRATION_TEST_LABEL ,
94+ & get_test_image ( ) ,
95+ disk_path. as_str ( ) ,
96+ ] ) ?;
97+
98+ assert ! (
99+ output. success( ) ,
100+ "to-disk failed with exit code: {:?}. stdout: {}, stderr: {}" ,
101+ output. exit_code( ) ,
102+ output. stdout,
103+ output. stderr
104+ ) ;
105+
106+ validate_disk_image ( & disk_path, & output, "test_to_disk" ) ?;
88107 Ok ( ( ) )
89108}
90109integration_test ! ( test_to_disk) ;
@@ -112,9 +131,6 @@ fn test_to_disk_qcow2() -> Result<()> {
112131 output. stderr
113132 ) ;
114133
115- let metadata = std:: fs:: metadata ( & disk_path) . expect ( "Failed to get disk metadata" ) ;
116- assert ! ( metadata. len( ) > 0 ) ;
117-
118134 // Verify the file is actually qcow2 format using qemu-img info
119135 let qemu_img_output = Command :: new ( "qemu-img" )
120136 . args ( [ "info" , disk_path. as_str ( ) ] )
@@ -135,11 +151,7 @@ fn test_to_disk_qcow2() -> Result<()> {
135151 qemu_img_stdout
136152 ) ;
137153
138- assert ! (
139- output. stdout. contains( "Installation complete" ) || output. stderr. contains( "Installation complete" ) ,
140- "No 'Installation complete' message found in output. This indicates bootc install did not complete successfully. stdout: {}, stderr: {}" ,
141- output. stdout, output. stderr
142- ) ;
154+ validate_disk_image ( & disk_path, & output, "test_to_disk_qcow2" ) ?;
143155 Ok ( ( ) )
144156}
145157integration_test ! ( test_to_disk_qcow2) ;
@@ -215,3 +227,38 @@ fn test_to_disk_caching() -> Result<()> {
215227 Ok ( ( ) )
216228}
217229integration_test ! ( test_to_disk_caching) ;
230+
231+ /// Test to-disk with various bootc images to ensure compatibility
232+ ///
233+ /// This parameterized test runs to-disk with multiple container images,
234+ /// particularly testing AlmaLinux which had cross-device link issues (issue #125)
235+ fn test_to_disk_multi_image ( image : & str ) -> Result < ( ) > {
236+ let temp_dir = TempDir :: new ( ) . expect ( "Failed to create temp directory" ) ;
237+ let disk_path = Utf8PathBuf :: try_from ( temp_dir. path ( ) . join ( "test-disk.img" ) )
238+ . expect ( "temp path is not UTF-8" ) ;
239+
240+ let output = run_bcvk ( & [
241+ "to-disk" ,
242+ "--label" ,
243+ INTEGRATION_TEST_LABEL ,
244+ image,
245+ disk_path. as_str ( ) ,
246+ ] ) ?;
247+
248+ assert ! (
249+ output. success( ) ,
250+ "to-disk with image {} failed with exit code: {:?}. stdout: {}, stderr: {}" ,
251+ image,
252+ output. exit_code( ) ,
253+ output. stdout,
254+ output. stderr
255+ ) ;
256+
257+ validate_disk_image (
258+ & disk_path,
259+ & output,
260+ & format ! ( "test_to_disk_multi_image({})" , image) ,
261+ ) ?;
262+ Ok ( ( ) )
263+ }
264+ parameterized_integration_test ! ( test_to_disk_multi_image) ;
0 commit comments