From 322974695cfd6fe3022d8ec4c968b368b674d4dc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 19 Feb 2024 10:03:36 +0100 Subject: [PATCH] stages(dracut): add small unittest for initoverlayfs Small followup for https://github.com/osbuild/osbuild/pull/1586 that includes a basic check that the initoverlayfs option calls the right binary. --- stages/test/test_dracut.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 stages/test/test_dracut.py diff --git a/stages/test/test_dracut.py b/stages/test/test_dracut.py new file mode 100644 index 00000000..c1e0f6a2 --- /dev/null +++ b/stages/test/test_dracut.py @@ -0,0 +1,30 @@ +#!/usr/bin/python3 + +from unittest.mock import patch + +import pytest + +STAGE_NAME = "org.osbuild.dracut" + + +@pytest.mark.parametrize("with_initoverlayfs,expected_argv2", [ + (False, "/usr/bin/dracut"), + (True, "/usr/bin/initoverlayfs-install"), +]) +@patch("subprocess.run") +def test_dracut_with_initoverlayfs(mocked_run, tmp_path, stage_module, with_initoverlayfs, expected_argv2): + options = { + "kernel": [ + "5.14.0-247.el9.x86_64" + ], + "initoverlayfs": with_initoverlayfs, + } + + stage_module.main(tmp_path, options) + + assert len(mocked_run.call_args_list) == 1 + args, kwargs = mocked_run.call_args_list[0] + assert kwargs.get("check") is True + run_argv = args[0] + assert run_argv[0] == "/usr/sbin/chroot" + assert run_argv[2] == expected_argv2