From 2a0027557f29ad4908f0bb39bc8019c4ff9ed6d5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Apr 2024 10:04:04 +0200 Subject: [PATCH] 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. --- stages/test/test_groups.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 stages/test/test_groups.py diff --git a/stages/test/test_groups.py b/stages/test/test_groups.py new file mode 100644 index 00000000..a3940a3f --- /dev/null +++ b/stages/test/test_groups.py @@ -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)