...

Text file src/github.com/emissary-ingress/emissary/v3/python/tests/unit/test_hcm.py

Documentation: github.com/emissary-ingress/emissary/v3/python/tests/unit

     1import pytest
     2
     3from tests.utils import econf_compile, econf_foreach_hcm, module_and_mapping_manifests
     4
     5
     6def _test_hcm(yaml, expectations={}):
     7    # Compile an envoy config
     8    econf = econf_compile(yaml)
     9
    10    # Make sure expectations pass for each HCM in the compiled config
    11    def check(typed_config):
    12        for key, expected in expectations.items():
    13            if expected is None:
    14                assert key not in typed_config
    15            else:
    16                assert key in typed_config
    17                assert typed_config[key] == expected
    18        return True
    19
    20    econf_foreach_hcm(econf, check)
    21
    22
    23@pytest.mark.compilertest
    24def test_strip_matching_host_port_missing():
    25    # If we do not set the config, it should be missing (noted in this test as None).
    26    yaml = module_and_mapping_manifests(None, [])
    27    _test_hcm(yaml, expectations={"strip_matching_host_port": None})
    28
    29
    30@pytest.mark.compilertest
    31def test_strip_matching_host_port_module_false():
    32    # If we set the config to false, it should be missing (noted in this test as None).
    33    yaml = module_and_mapping_manifests(["strip_matching_host_port: false"], [])
    34    _test_hcm(yaml, expectations={"strip_matching_host_port": None})
    35
    36
    37@pytest.mark.compilertest
    38def test_strip_matching_host_port_module_true():
    39    # If we set the config to true, it should show up as true.
    40    yaml = module_and_mapping_manifests(["strip_matching_host_port: true"], [])
    41    _test_hcm(yaml, expectations={"strip_matching_host_port": True})
    42
    43
    44@pytest.mark.compilertest
    45def test_merge_slashes_missing():
    46    # If we do not set the config, it should be missing (noted in this test as None).
    47    yaml = module_and_mapping_manifests(None, [])
    48    _test_hcm(yaml, expectations={"merge_slashes": None})
    49
    50
    51@pytest.mark.compilertest
    52def test_merge_slashes_module_false():
    53    # If we set the config to false, it should be missing (noted in this test as None).
    54    yaml = module_and_mapping_manifests(["merge_slashes: false"], [])
    55    _test_hcm(yaml, expectations={"merge_slashes": None})
    56
    57
    58@pytest.mark.compilertest
    59def test_merge_slashes_module_true():
    60    # If we set the config to true, it should show up as true.
    61    yaml = module_and_mapping_manifests(["merge_slashes: true"], [])
    62    _test_hcm(yaml, expectations={"merge_slashes": True})
    63
    64
    65@pytest.mark.compilertest
    66def test_reject_requests_with_escaped_slashes_missing():
    67    # If we set the config to false, the action should be missing.
    68    yaml = module_and_mapping_manifests(None, [])
    69    _test_hcm(yaml, expectations={"path_with_escaped_slashes_action": None})
    70
    71
    72@pytest.mark.compilertest
    73def test_reject_requests_with_escaped_slashes_false():
    74    # If we set the config to false, the action should be missing.
    75    yaml = module_and_mapping_manifests(["reject_requests_with_escaped_slashes: false"], [])
    76    _test_hcm(yaml, expectations={"path_with_escaped_slashes_action": None})
    77
    78
    79@pytest.mark.compilertest
    80def test_reject_requests_with_escaped_slashes_true():
    81    # If we set the config to true, the action should show up as "REJECT_REQUEST".
    82    yaml = module_and_mapping_manifests(["reject_requests_with_escaped_slashes: true"], [])
    83    _test_hcm(yaml, expectations={"path_with_escaped_slashes_action": "REJECT_REQUEST"})
    84
    85
    86@pytest.mark.compilertest
    87def test_preserve_external_request_id_missing():
    88    # If we do not set the config, it should be false
    89    yaml = module_and_mapping_manifests(None, [])
    90    _test_hcm(yaml, expectations={"preserve_external_request_id": False})
    91
    92
    93@pytest.mark.compilertest
    94def test_preserve_external_request_id_module_false():
    95    # If we set the config to false, it should be false
    96    yaml = module_and_mapping_manifests(["preserve_external_request_id: false"], [])
    97    _test_hcm(yaml, expectations={"preserve_external_request_id": False})
    98
    99
   100@pytest.mark.compilertest
   101def test_preserve_external_request_id_module_true():
   102    # If we set the config to true, it should show up as true.
   103    yaml = module_and_mapping_manifests(["preserve_external_request_id: true"], [])
   104    _test_hcm(yaml, expectations={"preserve_external_request_id": True})

View as plain text