summaryrefslogtreecommitdiff
path: root/tests/unittests/config/test_cc_scripts_vendor.py
blob: 9d3e90e0e0ca9eee2853aea19aaa1cbebe7fb59a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pytest

from cloudinit.config.schema import (
    SchemaValidationError,
    get_schema,
    validate_cloudconfig_schema,
)
from tests.unittests.helpers import does_not_raise, skipUnlessJsonSchema


class TestScriptsVendorSchema:
    @pytest.mark.parametrize(
        "config, expectation",
        (
            ({"vendor_data": {"enabled": True}}, does_not_raise()),
            ({"vendor_data": {"enabled": False}}, does_not_raise()),
            (
                {"vendor_data": {"enabled": "yes"}},
                pytest.raises(
                    SchemaValidationError,
                    match=(
                        "Cloud config schema deprecations: "
                        "vendor_data.enabled:  Deprecated in version "
                        "22.3. Use of type string for this value is "
                        "deprecated. Use a boolean instead."
                    ),
                ),
            ),
        ),
    )
    @skipUnlessJsonSchema()
    def test_schema_validation(self, config, expectation):
        """Assert expected schema validation and error messages."""
        # New-style schema $defs exist in config/cloud-init-schema*.json
        schema = get_schema()
        with expectation:
            validate_cloudconfig_schema(config, schema, strict=True)