summaryrefslogtreecommitdiff
path: root/tests/unittests/config/test_cc_scripts_vendor.py
blob: 1dcd0573bdf6a34b2a21ffe19e1683addd92138e (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
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=(
                        "deprecations: vendor_data.enabled: DEPRECATED."
                        " Use of string for this value is DEPRECATED."
                        " Use a boolean value 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)