From 2b86adee37243dace9e0bed7b93a1e2ec77ed009 Mon Sep 17 00:00:00 2001 From: Lucas Moura Date: Tue, 5 May 2020 18:37:34 -0300 Subject: [PATCH 1/2] Create tests to validate schema examples --- cloudinit/config/cc_snap.py | 4 ++-- tests/unittests/test_handler/test_schema.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cloudinit/config/cc_snap.py b/cloudinit/config/cc_snap.py index 90724b81c04..fbe7787a56a 100644 --- a/cloudinit/config/cc_snap.py +++ b/cloudinit/config/cc_snap.py @@ -61,9 +61,9 @@ snap: assertions: 00: | - signed_assertion_blob_here + signed_assertion_blob_here 02: | - signed_assertion_blob_here + signed_assertion_blob_here commands: 00: snap create-user --sudoer --known @mydomain.com 01: snap install canonical-livepatch diff --git a/tests/unittests/test_handler/test_schema.py b/tests/unittests/test_handler/test_schema.py index 1059fb8b406..927fb48f057 100644 --- a/tests/unittests/test_handler/test_schema.py +++ b/tests/unittests/test_handler/test_schema.py @@ -10,6 +10,7 @@ from copy import copy import os +import pytest from io import StringIO from textwrap import dedent from yaml import safe_load @@ -112,6 +113,23 @@ def test_validateconfig_schema_honors_formats(self): 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) + 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.""" From 7d64f901e83aed504cf572e4af5d99609679ff8e Mon Sep 17 00:00:00 2001 From: Lucas Moura Date: Wed, 6 May 2020 08:51:44 -0300 Subject: [PATCH 2/2] Add skipUnlessJsonSchema decorator to test --- tests/unittests/test_handler/test_schema.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unittests/test_handler/test_schema.py b/tests/unittests/test_handler/test_schema.py index 927fb48f057..ae3838d87c8 100644 --- a/tests/unittests/test_handler/test_schema.py +++ b/tests/unittests/test_handler/test_schema.py @@ -121,6 +121,7 @@ class TestCloudConfigExamples: 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