states(users): move to schema_2 to allow adding mounts/devices

This is a preparation to allow adding mounts/devices to the users
stage so that we can eventually support bootc install to-filesystem.

It also adds some smoke tests for the schema to ensure it's still
valid.
This commit is contained in:
Michael Vogt 2024-04-05 09:32:22 +02:00 committed by Achilleas Koutsou
parent 35fbf6a377
commit 72a2334fbe
2 changed files with 81 additions and 54 deletions

View file

@ -4,10 +4,35 @@ from unittest.mock import patch
import pytest
from osbuild.testutil import make_fake_tree, mock_command
from osbuild.testutil import assert_jsonschema_error_contains, make_fake_tree, mock_command
STAGE_NAME = "org.osbuild.users"
@pytest.mark.parametrize("test_data,expected_err", [
# bad
({"users": {"!invalid-name": {}}}, "'!invalid-name' does not match any of the regex"),
({"users": {"foo": {"home": 0}}}, "0 is not of type 'string'"),
# good
({}, ""),
({"users": {"foo": {}}}, ""),
])
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)
TEST_CASES = [
# user_opts,expected commandline args
({}, []),