From 4f4bddcc758303022ba4a0aa46d9c77d5593a625 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 16 Apr 2024 09:01:17 +0200 Subject: [PATCH] test: add "functional" test for devices/mounts acceptance This test ensures that the inputs of devices/mounts we generate for bootc are actually considered valid by the schema. This is a more blackbox style test compared to `test_get_schema_automatically_added` which just checks that we get the expected schema but not that the expected schema actually parses our inputs. --- test/mod/test_meta.py | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test/mod/test_meta.py b/test/mod/test_meta.py index 6adbe5ba..419199a6 100644 --- a/test/mod/test_meta.py +++ b/test/mod/test_meta.py @@ -359,3 +359,57 @@ def test_get_schema_automatically_added(tmp_path, property_key, expected_value): modinfo = osbuild.meta.ModuleInfo.load(tmp_path, "Stage", "org.osbuild.noop") json_schema = modinfo.get_schema() assert json_schema["properties"][property_key] == expected_value + + +@pytest.fixture(name="bootc_devices_mounts_dict") +def bootc_devices_mounts_dict_fixture() -> dict: + """ bootc_devices_mounts_dict returns a dict with a typical bootc + devices/mount dict + """ + return { + "devices": { + "disk": { + "type": "org.osbuild.loopback", + "options": { + "filename": "disk.raw", + "partscan": True, + } + } + }, + "mounts": [ + { + "name": "root", + "type": "org.osbuild.ext4", + "source": "disk", + "partition": 4, + "target": "/" + }, { + "name": "ostree.deployment", + "type": "org.osbuild.ostree.deployment", + "options": { + "source": "mount", + "deployment": { + "default": True, + } + } + } + ] + } + + +@pytest.mark.parametrize("fmt_ver,name_or_type_key", [ + (1, "name"), + (2, "type"), +]) +def test_get_schema_devices_mounts_works(tmp_path, bootc_devices_mounts_dict, fmt_ver, name_or_type_key): + stage_name = "org.osbuild.noop" + + fake_stage = bootc_devices_mounts_dict + fake_stage[name_or_type_key] = stage_name + + make_fake_meta_json(tmp_path, stage_name, version=fmt_ver) + modinfo = osbuild.meta.ModuleInfo.load(tmp_path, "Stage", stage_name) + json_schema = modinfo.get_schema(version=str(fmt_ver)) + stage_schema = osbuild.meta.Schema(json_schema, stage_name) + res = stage_schema.validate(fake_stage) + assert res.valid is True, f"err: {[e.as_dict() for e in res.errors]}"