test(stages/skopeo): schema validation
Minor schema validation test.
This commit is contained in:
parent
852a76cc5c
commit
2141168e44
1 changed files with 42 additions and 0 deletions
42
stages/test/test_skopeo.py
Normal file
42
stages/test/test_skopeo.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
|
||||
import osbuild.meta
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_data,expected_err", [
|
||||
# bad
|
||||
({}, "'destination' is a required property"),
|
||||
({"destination": {}}, "is not valid under any of the given schemas"),
|
||||
({"destination": {"type": "foo"}}, "is not valid under any of the given schemas"),
|
||||
({"destination": {"type": "oci"}}, "is not valid under any of the given schemas"),
|
||||
# good
|
||||
({"destination": {"type": "oci", "path": "/foo"}}, ""),
|
||||
|
||||
# this one might not be expected but it's valid because we don't require any
|
||||
# *inputs* and it'll be a no-op in the stage
|
||||
({"destination": {"type": "containers-storage"}}, ""),
|
||||
])
|
||||
def test_schema_validation_skopeo(test_data, expected_err):
|
||||
name = "org.osbuild.skopeo"
|
||||
root = os.path.join(os.path.dirname(__file__), "../..")
|
||||
mod_info = osbuild.meta.ModuleInfo.load(root, "Stage", name)
|
||||
schema = osbuild.meta.Schema(mod_info.get_schema(version="2"), name)
|
||||
|
||||
test_input = {
|
||||
"type": "org.osbuild.skopeo",
|
||||
"options": {},
|
||||
}
|
||||
test_input["options"].update(test_data)
|
||||
res = 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 len(res.errors) == 1, [e.as_dict() for e in res.errors]
|
||||
err_msgs = [e.as_dict()["message"] for e in res.errors]
|
||||
assert expected_err in err_msgs[0]
|
||||
Loading…
Add table
Add a link
Reference in a new issue