stages: add test for bootc.install-to-filesystem

This commit is contained in:
Michael Vogt 2024-01-19 12:39:52 +01:00 committed by Achilleas Koutsou
parent 226b50eba5
commit af360b0d71

View file

@ -0,0 +1,50 @@
#!/usr/bin/python3
import os.path
from contextlib import contextmanager
from unittest.mock import patch
from osbuild.testutil.imports import import_module_from_path
@patch("subprocess.run")
def test_bootc_install_to_fs(mock_run, tmp_path):
stage_path = os.path.join(os.path.dirname(__file__), "../org.osbuild.bootc.install-to-filesystem")
stage = import_module_from_path("bootc_install_to_fs_stage", stage_path)
inputs = {
"images": {
"path": "/input/images/path",
"data": {
"archives": {
"/input/images/path": {
"format": "oci-archive",
"name": "some-img-name",
},
},
},
},
}
mounts = {
"root": {
"path": "/path/to/root",
},
}
@contextmanager
def faked_tmp_dir():
yield tmp_path
with patch("tempfile.TemporaryDirectory", side_effect=faked_tmp_dir):
stage.main(inputs, mounts)
assert len(mock_run.call_args_list) == 1
args = mock_run.call_args_list[0].args
assert len(args) == 1
assert args[0] == [
"bootc", "install", "to-filesystem",
"--source-imgref", f"oci-archive:{tmp_path}/image",
"--skip-fetch-check", "--generic-image",
"/path/to/root",
]
kwargs = mock_run.call_args_list[0].kwargs
assert kwargs["check"] is True