summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_handler/test_schema.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/tests/unittests/test_handler/test_schema.py b/tests/unittests/test_handler/test_schema.py
index ae3838d8..071b98bc 100644
--- a/tests/unittests/test_handler/test_schema.py
+++ b/tests/unittests/test_handler/test_schema.py
@@ -1,5 +1,5 @@
# This file is part of cloud-init. See LICENSE file for license information.
-
+import cloudinit
from cloudinit.config.schema import (
CLOUD_CONFIG_HEADER, SchemaValidationError, annotated_cloudconfig_file,
get_schema_doc, get_schema, validate_cloudconfig_file,
@@ -12,6 +12,7 @@ from copy import copy
import os
import pytest
from io import StringIO
+from pathlib import Path
from textwrap import dedent
from yaml import safe_load
@@ -114,13 +115,12 @@ class ValidateCloudConfigSchemaTest(CiTestCase):
class TestCloudConfigExamples:
-
- SCHEMA = get_schema()
- PARAMS = [
+ schema = get_schema()
+ params = [
(schema["id"], example)
- for schema in SCHEMA["allOf"] for example in schema["examples"]]
+ for schema in schema["allOf"] for example in schema["examples"]]
- @pytest.mark.parametrize("schema_id,example", PARAMS)
+ @pytest.mark.parametrize("schema_id,example", params)
@skipUnlessJsonSchema()
def test_validateconfig_schema_of_example(self, schema_id, example):
""" For a given example in a config module we test if it is valid
@@ -128,7 +128,7 @@ class TestCloudConfigExamples:
"""
config_load = safe_load(example)
validate_cloudconfig_schema(
- config_load, TestCloudConfigExamples.SCHEMA, strict=True)
+ config_load, self.schema, strict=True)
class ValidateCloudConfigFileTest(CiTestCase):
@@ -447,4 +447,23 @@ class CloudTestsIntegrationTest(CiTestCase):
if errors:
raise AssertionError(', '.join(errors))
+
+def _get_schema_doc_examples():
+ examples_dir = Path(
+ cloudinit.__file__).parent.parent / 'doc' / 'examples'
+ assert examples_dir.is_dir()
+
+ all_text_files = (f for f in examples_dir.glob('cloud-config*.txt')
+ if not f.name.startswith('cloud-config-archive'))
+ return all_text_files
+
+
+class TestSchemaDocExamples:
+ schema = get_schema()
+
+ @pytest.mark.parametrize("example_path", _get_schema_doc_examples())
+ @skipUnlessJsonSchema()
+ def test_schema_doc_examples(self, example_path):
+ validate_cloudconfig_file(str(example_path), self.schema)
+
# vi: ts=4 expandtab syntax=python