From 2141168e445a127bef767dfe2ef82eebb0b85367 Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Tue, 12 Dec 2023 09:45:36 +0100 Subject: [PATCH] test(stages/skopeo): schema validation Minor schema validation test. --- stages/test/test_skopeo.py | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 stages/test/test_skopeo.py diff --git a/stages/test/test_skopeo.py b/stages/test/test_skopeo.py new file mode 100644 index 00000000..6e84ef62 --- /dev/null +++ b/stages/test/test_skopeo.py @@ -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]