|
| 1 | +""" |
| 2 | +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | +SPDX-License-Identifier: MIT-0 |
| 4 | +""" |
| 5 | + |
| 6 | +from collections import deque |
| 7 | + |
| 8 | +import pytest |
| 9 | + |
| 10 | +from cfnlint.jsonschema import ValidationError |
| 11 | + |
| 12 | +# ruff: noqa: E501 |
| 13 | +from cfnlint.rules.resources.elasticloadbalancingv2.TargetGroupHealthCheckProtocolRestrictions import ( |
| 14 | + TargetGroupHealthCheckProtocolRestrictions, |
| 15 | +) |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture(scope="module") |
| 19 | +def rule(): |
| 20 | + rule = TargetGroupHealthCheckProtocolRestrictions() |
| 21 | + yield rule |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.parametrize( |
| 25 | + "instance,expected", |
| 26 | + [ |
| 27 | + ( |
| 28 | + {"HealthCheckProtocol": "HTTPS", "Matcher": {}}, |
| 29 | + [], |
| 30 | + ), |
| 31 | + ( |
| 32 | + {"HealthCheckProtocol": "TCP"}, |
| 33 | + [], |
| 34 | + ), |
| 35 | + ( |
| 36 | + [], |
| 37 | + [], |
| 38 | + ), |
| 39 | + ( |
| 40 | + {"HealthCheckProtocol": "TCP", "Matcher": {}}, |
| 41 | + [ |
| 42 | + ValidationError( |
| 43 | + "Additional properties are not allowed ('Matcher' was unexpected)", |
| 44 | + rule=TargetGroupHealthCheckProtocolRestrictions(), |
| 45 | + validator="additionalProperties", |
| 46 | + path=deque(["Matcher"]), |
| 47 | + schema_path=deque( |
| 48 | + ["then", "allOf", 0, "else", "properties", "Matcher"] |
| 49 | + ), |
| 50 | + ) |
| 51 | + ], |
| 52 | + ), |
| 53 | + ], |
| 54 | +) |
| 55 | +def test_backup_lifecycle(instance, expected, rule, validator): |
| 56 | + errs = list(rule.validate(validator, "", instance, {})) |
| 57 | + assert errs == expected, f"Expected {expected} got {errs}" |
0 commit comments