...

Text file src/github.com/emissary-ingress/emissary/v3/python/tests/unit/test_route.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_route(yaml, expectations={}):
     7    econf = econf_compile(yaml)
     8
     9    def check(typed_config):
    10        # Find the one and virtual host in the route config
    11        vhosts = typed_config["route_config"]["virtual_hosts"]
    12        assert len(vhosts) == 1
    13
    14        # Find the httpbin route. Run our expectations over that.
    15        routes = vhosts[0]["routes"]
    16        for r in routes:
    17            # Keep going until we find a real route
    18            if "route" not in r:
    19                continue
    20
    21            # Keep going until we find a prefix match for /httpbin/
    22            match = r["match"]
    23            if "prefix" not in match or match["prefix"] != "/httpbin/":
    24                continue
    25
    26            assert "route" in r
    27            route = r["route"]
    28            for key, expected in expectations.items():
    29                print("checking key %s" % key)
    30                assert key in route
    31                assert route[key] == expected
    32            break
    33
    34    econf_foreach_hcm(econf, check)
    35
    36
    37@pytest.mark.compilertest
    38def test_timeout_ms():
    39    # If we do not set the config, we should get the default 3000ms.
    40    yaml = module_and_mapping_manifests(None, [])
    41    _test_route(yaml, expectations={"timeout": "3.000s"})
    42
    43
    44@pytest.mark.compilertest
    45def test_timeout_ms_module():
    46    # If we set a default on the Module, it should override the usual default of 3000ms.
    47    yaml = module_and_mapping_manifests(["cluster_request_timeout_ms: 4000"], [])
    48    _test_route(yaml, expectations={"timeout": "4.000s"})
    49
    50
    51@pytest.mark.compilertest
    52def test_timeout_ms_mapping():
    53    # If we set a default on the Module, it should override the usual default of 3000ms.
    54    yaml = module_and_mapping_manifests(None, ["timeout_ms: 1234"])
    55    _test_route(yaml, expectations={"timeout": "1.234s"})
    56
    57
    58@pytest.mark.compilertest
    59def test_timeout_ms_both():
    60    # If we set a default on the Module, it should override the usual default of 3000ms.
    61    yaml = module_and_mapping_manifests(["cluster_request_timeout_ms: 9000"], ["timeout_ms: 5001"])
    62    _test_route(yaml, expectations={"timeout": "5.001s"})

View as plain text