test/rpm: add schema validation test for boot_root

This commit is contained in:
Michael Vogt 2025-03-12 16:14:03 +01:00 committed by Tomáš Hozza
parent 2e45963aed
commit e93cd75e5b

28
stages/test/test_rpm.py Normal file
View file

@ -0,0 +1,28 @@
import pytest
from osbuild import testutil
STAGE_NAME = "org.osbuild.rpm"
@pytest.mark.parametrize("test_data,expected_err", [
# bad
({"kernel_install_env": {"boot_root": "../rel"}}, "'../rel' does not match "),
# good
({}, ""),
({"kernel_install_env": {"boot_root": "/boot"}}, ""),
])
def test_schema_validation(stage_schema, test_data, expected_err):
test_input = {
"type": STAGE_NAME,
"options": {
}
}
test_input["options"].update(test_data)
res = stage_schema.validate(test_input)
if expected_err == "":
assert res.valid is True, f"err: {[e.as_dict() for e in res.errors]}"
else:
assert res.valid is False
testutil.assert_jsonschema_error_contains(res, expected_err, expected_num_errs=1)