diff options
author | lucasmoura <lucas.moura@canonical.com> | 2020-05-06 17:19:35 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-06 14:19:35 -0600 |
commit | 022122a54e895468d054ed162fdf1b403b7aaf3f (patch) | |
tree | 1afbfe9394ca1f9f8f3374c63ca4b6c32457aca8 /tests | |
parent | 73d8748e797134fa0a06415b6cb16be2e05abc7e (diff) | |
download | vyos-cloud-init-022122a54e895468d054ed162fdf1b403b7aaf3f.tar.gz vyos-cloud-init-022122a54e895468d054ed162fdf1b403b7aaf3f.zip |
Create tests to validate schema examples (#348)
Add a unit test to validate if the examples provided in the config
modules are conforming to the concatenated schema of all config
modules. The rationale behind that is not only to verify if the
examples are correctly written but to assert that no config schema
is interfering with each other.
Failures in validate_cloudconfig_schema raise the
SchemaValidationError by using strict=True, so I have
only called the function passing the right schema examples to
validate.
This branch also fixes an invalid schema example in cc_snap.
LP: #1876412
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_handler/test_schema.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/unittests/test_handler/test_schema.py b/tests/unittests/test_handler/test_schema.py index 1059fb8b..ae3838d8 100644 --- a/tests/unittests/test_handler/test_schema.py +++ b/tests/unittests/test_handler/test_schema.py @@ -10,6 +10,7 @@ from cloudinit.tests.helpers import CiTestCase, mock, skipUnlessJsonSchema from copy import copy import os +import pytest from io import StringIO from textwrap import dedent from yaml import safe_load @@ -112,6 +113,24 @@ class ValidateCloudConfigSchemaTest(CiTestCase): str(context_mgr.exception)) +class TestCloudConfigExamples: + + SCHEMA = get_schema() + PARAMS = [ + (schema["id"], example) + for schema in SCHEMA["allOf"] for example in schema["examples"]] + + @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 + according to the unified schema of all config modules + """ + config_load = safe_load(example) + validate_cloudconfig_schema( + config_load, TestCloudConfigExamples.SCHEMA, strict=True) + + class ValidateCloudConfigFileTest(CiTestCase): """Tests for validate_cloudconfig_file.""" |