@@ -196,8 +196,8 @@ def test_enforce_json_config_dir_multiple_chunks_input(tmpdir):
196196 '{"one_more": "chunk", "createdAt": "2025-01-21T07:15:29"}'
197197 )
198198
199- input = os .path .join (tmpdir , f "test_file.yaml" )
200- output = os .path .join (tmpdir , f "test_file.json" )
199+ input = os .path .join (tmpdir , "test_file.yaml" )
200+ output = os .path .join (tmpdir , "test_file.json" )
201201 with open (input , 'w' ) as w :
202202 w .write (dedent (multiple_chunks_yaml ))
203203
@@ -213,15 +213,82 @@ def test_enforce_json_config_dir_multiple_chunks_input(tmpdir):
213213def test_extract_fbc_fragment (mock_cffi , mock_osldr , ldr_output , tmpdir ):
214214 test_fbc_fragment = "example.com/test/fbc_fragment:latest"
215215 mock_osldr .return_value = ldr_output
216- fbc_fragment_path = os .path .join (tmpdir , get_worker_config ()['temp_fbc_fragment_path' ])
216+ # The function now adds -0 suffix by default when fragment_index is not provided
217+ fbc_fragment_path = os .path .join (tmpdir , f"{ get_worker_config ()['temp_fbc_fragment_path' ]} -0" )
217218
218219 if not ldr_output :
219220 with pytest .raises (IIBError ):
220221 extract_fbc_fragment (tmpdir , test_fbc_fragment )
221222 else :
222223 extract_fbc_fragment (tmpdir , test_fbc_fragment )
223- mock_cffi .assert_has_calls ([mock .call (test_fbc_fragment , '/configs' , fbc_fragment_path )])
224- mock_osldr .assert_has_calls ([mock .call (fbc_fragment_path )])
224+ mock_cffi .assert_called_once_with (
225+ test_fbc_fragment , get_worker_config ()['fbc_fragment_catalog_path' ], fbc_fragment_path
226+ )
227+ mock_osldr .assert_called_once_with (fbc_fragment_path )
228+
229+
230+ @pytest .mark .parametrize ('ldr_output' , [['testoperator' ], ['test1' , 'test2' ]])
231+ @mock .patch ('os.listdir' )
232+ @mock .patch ('iib.workers.tasks.build._copy_files_from_image' )
233+ def test_extract_fbc_fragment_with_index (mock_cffi , mock_osldr , ldr_output , tmpdir ):
234+ """Test extract_fbc_fragment with non-zero fragment_index values."""
235+ test_fbc_fragment = "example.com/test/fbc_fragment:latest"
236+ mock_osldr .return_value = ldr_output
237+
238+ # Test with fragment_index = 2
239+ fragment_index = 2
240+ fbc_fragment_path = os .path .join (
241+ tmpdir , f"{ get_worker_config ()['temp_fbc_fragment_path' ]} -{ fragment_index } "
242+ )
243+
244+ result_path , result_operators = extract_fbc_fragment (
245+ tmpdir , test_fbc_fragment , fragment_index = fragment_index
246+ )
247+
248+ # Verify the path includes the correct index
249+ assert result_path == fbc_fragment_path
250+ assert result_path .endswith (f"-{ fragment_index } " )
251+ assert result_operators == ldr_output
252+
253+ # Verify the function was called with the correct path
254+ mock_cffi .assert_called_once_with (
255+ test_fbc_fragment , get_worker_config ()['fbc_fragment_catalog_path' ], fbc_fragment_path
256+ )
257+ mock_osldr .assert_called_once_with (fbc_fragment_path )
258+
259+
260+ @mock .patch ('os.listdir' )
261+ @mock .patch ('iib.workers.tasks.build._copy_files_from_image' )
262+ def test_extract_fbc_fragment_isolation (mock_cffi , mock_osldr , tmpdir ):
263+ """Test that multiple fragments with different indices create isolated directories."""
264+ test_fbc_fragment1 = "example.com/test/fbc_fragment1:latest"
265+ test_fbc_fragment2 = "example.com/test/fbc_fragment2:latest"
266+
267+ # Mock different outputs for each fragment
268+ mock_osldr .side_effect = [['operator1' ], ['operator2' ]]
269+
270+ # Extract first fragment with index 0
271+ path1 , operators1 = extract_fbc_fragment (tmpdir , test_fbc_fragment1 , fragment_index = 0 )
272+
273+ # Extract second fragment with index 1
274+ path2 , operators2 = extract_fbc_fragment (tmpdir , test_fbc_fragment2 , fragment_index = 1 )
275+
276+ # Verify paths are different and include correct indices
277+ assert path1 != path2
278+ assert path1 .endswith ("-0" )
279+ assert path2 .endswith ("-1" )
280+
281+ # Verify operators are different (no cross-contamination)
282+ assert operators1 == ['operator1' ]
283+ assert operators2 == ['operator2' ]
284+ assert operators1 != operators2
285+
286+ # Verify _copy_files_from_image was called with different paths
287+ expected_calls = [
288+ mock .call (test_fbc_fragment1 , get_worker_config ()['fbc_fragment_catalog_path' ], path1 ),
289+ mock .call (test_fbc_fragment2 , get_worker_config ()['fbc_fragment_catalog_path' ], path2 ),
290+ ]
291+ mock_cffi .assert_has_calls (expected_calls , any_order = True )
225292
226293
227294def test__serialize_datetime ():
@@ -231,5 +298,5 @@ def test__serialize_datetime():
231298
232299
233300def test__serialize_datetime_raise ():
234- with pytest .raises (TypeError , match = f "Type <class 'int'> is not serializable." ):
301+ with pytest .raises (TypeError , match = "Type <class 'int'> is not serializable." ):
235302 _serialize_datetime (2025 )
0 commit comments