stages/test: add unit tests for the dnf4.versionlock stage
This commit is contained in:
parent
06344b6827
commit
ece618d0d0
1 changed files with 51 additions and 0 deletions
51
stages/test/test_dnf4_versionlock.py
Normal file
51
stages/test/test_dnf4_versionlock.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/python3
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from osbuild import testutil
|
||||
|
||||
STAGE_NAME = "org.osbuild.dnf4.versionlock"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_data,expected_err", [
|
||||
# bad
|
||||
({}, "'add' is a required property"),
|
||||
# good
|
||||
({"add": ["shim-x64-*"]}, ""),
|
||||
({"add": ["proto-1:1.1", "deftero-0:2.2", "trito-3:3.3-3.fc33"]}, ""),
|
||||
])
|
||||
def test_schema_validation_dnf4_versionlock(stage_schema, test_data, expected_err):
|
||||
test_input = {
|
||||
"type": STAGE_NAME,
|
||||
"options": 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)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_data", [
|
||||
({"add": ["shim-x64-*"]}),
|
||||
({"add": ["proto-1:1.1", "deftero-0:2.2", "trito-3:3.3-3.fc33"]}),
|
||||
])
|
||||
def test_locklist_dnf4_versionlock(tmp_path, stage_module, test_data):
|
||||
plugins_dir = os.path.join(tmp_path, "etc/dnf/plugins/")
|
||||
locklist_path = os.path.join(plugins_dir, "versionlock.list")
|
||||
os.makedirs(plugins_dir)
|
||||
stage_module.main(tmp_path, test_data)
|
||||
|
||||
with open(locklist_path, mode="r", encoding="utf-8") as locklist_fp:
|
||||
locklist_data = locklist_fp.readlines()
|
||||
|
||||
for idx, package in enumerate(test_data["add"]):
|
||||
assert locklist_data[idx * 3] == "\n"
|
||||
|
||||
# let's ignore the timestamp, just check that the comment was written
|
||||
assert locklist_data[idx * 3 + 1].startswith("# Added lock on")
|
||||
|
||||
assert locklist_data[idx * 3 + 2] == package + "\n"
|
||||
Loading…
Add table
Add a link
Reference in a new issue