stages(groups): add minimal parameter validation test
The schema will move to v2 so we need to ensure that at least some minimal validation is done that the old and the new schema work the same way.
This commit is contained in:
parent
588ffcfec3
commit
2a0027557f
1 changed files with 31 additions and 0 deletions
31
stages/test/test_groups.py
Normal file
31
stages/test/test_groups.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import pytest
|
||||
|
||||
from osbuild.testutil import assert_jsonschema_error_contains
|
||||
|
||||
STAGE_NAME = "org.osbuild.groups"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_data,expected_err", [
|
||||
# bad
|
||||
({"groups": {"!invalid-name": {}}}, "'!invalid-name' does not match any of the regex"),
|
||||
({"groups": {"foo": {"gid": "x"}}}, "'x' is not of type 'number'"),
|
||||
# good
|
||||
({}, ""),
|
||||
({"groups": {"foo": {}}}, ""),
|
||||
({"groups": {"foo": {"gid": 999}}}, ""),
|
||||
])
|
||||
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
|
||||
assert_jsonschema_error_contains(res, expected_err, expected_num_errs=1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue