diff --git a/tests/test_rpm_verifier.py b/tests/test_rpm_verifier.py index 79b84a9..0ee64fe 100644 --- a/tests/test_rpm_verifier.py +++ b/tests/test_rpm_verifier.py @@ -8,7 +8,12 @@ from pytest import MonkeyPatch from verify_rpms import rpm_verifier -from verify_rpms.rpm_verifier import ImageProcessor, ProcessedImage, generate_output +from verify_rpms.rpm_verifier import ( + ImageProcessor, + ProcessedImage, + generate_output, + get_rpmdb, +) @pytest.mark.parametrize( @@ -130,6 +135,19 @@ def test_call( assert out == ProcessedImage(image=img, unsigned_rpms=unsigned_rpms) +def test_get_rpmdb(tmp_path: Path) -> None: + """Test get_rpmdb""" + image = "my-image" + mock_runner = MagicMock() + out = get_rpmdb( + container_image=image, + target_dir=tmp_path, + runner=mock_runner, + ) + assert mock_runner.call_count == 1 + assert out == tmp_path + + class TestMain: """Test call to rpm_verifier.py main function""" diff --git a/verify_rpms/rpm_verifier.py b/verify_rpms/rpm_verifier.py index 8a54b41..5264a17 100644 --- a/verify_rpms/rpm_verifier.py +++ b/verify_rpms/rpm_verifier.py @@ -26,7 +26,20 @@ def __str__(self) -> str: def get_rpmdb(container_image: str, target_dir: Path, runner: Callable = run) -> Path: """Extract RPM DB from a given container image reference""" - raise NotImplementedError() + runner( + [ + "oc", + "image", + "extract", + container_image, + "--path", + f"/var/lib/rpm/:{target_dir}", + ], + capture_output=True, + text=True, + check=True, + ) + return target_dir def get_unsigned_rpms(rpmdb: Path, runner: Callable = run) -> list[str]: