From 542cf4a7995650c4dab7041c7636b08e3aa1bcce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Tue, 21 Jan 2025 14:27:51 +0100 Subject: [PATCH] Test/osbuild-image-info: test failure on empty report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test that the main() function exits with non-zero value if it would return an empty report. Signed-off-by: Tomáš Hozza --- tools/test/test_osbuild_image_info.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/test/test_osbuild_image_info.py b/tools/test/test_osbuild_image_info.py index 3b22ce85..9ddd9aee 100644 --- a/tools/test/test_osbuild_image_info.py +++ b/tools/test/test_osbuild_image_info.py @@ -1,3 +1,6 @@ +import os +from unittest.mock import patch + import pytest from osbuild.testutil import make_fake_tree @@ -173,3 +176,14 @@ def test_read_default_target_none(tmp_path): Test the case when when there is no default target set on the system """ assert osbuild_image_info.read_default_target(tmp_path) == "" + + +# root is needed, because the script will bind mount the dir as read-only +@pytest.mark.skipif(os.getuid() != 0, reason="root only") +def test_empty_report_fail(tmp_path): + """ + Test that the main() exits with a non-zero exit code if the report is empty. + """ + with pytest.raises(SystemExit) as e, patch("sys.argv", ["osbuild-image-info", str(tmp_path)]): + osbuild_image_info.main() + assert e.value.code == 1