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.
This commit is contained in:
Michael Vogt 2024-02-19 10:03:36 +01:00 committed by Ondřej Budai
parent 6b0d2d7a3c
commit 322974695c

View file

@ -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