From 5ec5c892bfb651940e87aa1825c221bfaec1b01e Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Fri, 10 May 2024 12:08:00 +0100 Subject: [PATCH] stages/oscap.autotailor: add json import unit test Add a small unit test for the json tailoring file import. --- stages/test/test_autotailor.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/stages/test/test_autotailor.py b/stages/test/test_autotailor.py index 2fe2ec3f..b9e90fd0 100644 --- a/stages/test/test_autotailor.py +++ b/stages/test/test_autotailor.py @@ -51,6 +51,20 @@ def fake_input_fixture(): } +@pytest.fixture(name="fake_json_input") +def fake_json_input_fixture(): + return { + "name": STAGE_NAME, + "options": { + "filepath": "tailoring-output.xml", + "config": { + "datastream": "some-datastream", + "tailoring_file": "tailoring-file.json", + } + }, + } + + @pytest.mark.parametrize("test_overrides,expected", TEST_INPUT) @patch("subprocess.run") def test_oscap_autotailor_overrides_smoke(mock_subprocess_run, fake_input, stage_module, test_overrides, expected): @@ -105,3 +119,14 @@ def test_schema_validation_oscap_autotailor(fake_input, stage_schema, test_data, assert res.valid is False testutil.assert_jsonschema_error_contains(res, expected_err, expected_num_errs=1) + + +@patch("subprocess.run") +def test_oscap_autotailor_json_smoke(mock_subprocess_run, fake_json_input, stage_module): + options = fake_json_input["options"] + stage_module.main("/some/sysroot", options) + + assert mock_subprocess_run.call_args_list == [ + call(["/usr/bin/autotailor", "--output", "/some/sysroot/tailoring-output.xml", + "--json-tailoring", "/some/sysroot/tailoring-file.json", "some-datastream"], + encoding='utf8', stdout=sys.stderr, check=True)]