def _test_route(yaml, expectations={}): econf = econf_compile(yaml) def check(typed_config): # Find the one and virtual host in the route config vhosts = typed_config['route_config']['virtual_hosts'] assert len(vhosts) == 1 # Find the httpbin route. Run our expectations over that. routes = vhosts[0]['routes'] for r in routes: # Keep going until we find a real route if 'route' not in r: continue # Keep going until we find a prefix match for /httpbin/ match = r['match'] if 'prefix' not in match or match['prefix'] != '/httpbin/': continue assert 'route' in r route = r['route'] for key, expected in expectations.items(): print("checking key %s" % key) assert key in route assert route[key] == expected break econf_foreach_hcm(econf, check)
def _test_router(yaml, expectations={}): for v in SUPPORTED_ENVOY_VERSIONS: econf = econf_compile(yaml, envoy_version=v) def check(typed_config): http_filters = typed_config['http_filters'] assert len(http_filters) == 2 # Find the typed router config, and run our uexpecations over that. for http_filter in http_filters: if http_filter['name'] != 'envoy.filters.http.router': continue # If we expect nothing, then the typed config should be missing entirely. if len(expectations) == 0: assert 'typed_config' not in http_filter break assert 'typed_config' in http_filter typed_config = http_filter['typed_config'] if v == 'V2': assert typed_config['@type'] == 'type.googleapis.com/envoy.config.filter.http.router.v2.Router' else: assert typed_config['@type'] == 'type.googleapis.com/envoy.extensions.filters.http.router.v3.Router' for key, expected in expectations.items(): print("checking key %s" % key) assert key in typed_config assert typed_config[key] == expected break econf_foreach_hcm(econf, check, envoy_version=v)
def _test_hcm(yaml, expectations={}): # Compile an envoy config econf = econf_compile(yaml) # Make sure expectations pass for each HCM in the compiled config def check(typed_config): for key, expected in expectations.items(): if expected is None: assert key not in typed_config else: assert key in typed_config assert typed_config[key] == expected return True econf_foreach_hcm(econf, check)
def _test_listener_common_http_protocol_options(yaml, expectations={}): # Compile an envoy config econf = econf_compile(yaml) # Make sure expectations pass for each HCM in the compiled config def check(typed_config): for key, expected in expectations.items(): if expected is None: assert key not in typed_config['common_http_protocol_options'] else: assert key in typed_config['common_http_protocol_options'] assert typed_config['common_http_protocol_options'][key] == expected return True econf_foreach_hcm(econf, check)
def _test_listener_http_protocol_options(yaml, expectations={}): for v in SUPPORTED_ENVOY_VERSIONS: # Compile an envoy config econf = econf_compile(yaml, envoy_version=v) # Make sure expectations pass for each HCM in the compiled config def check(typed_config): for key, expected in expectations.items(): if expected is None: assert key not in typed_config['http_protocol_options'] else: assert key in typed_config['http_protocol_options'] assert typed_config['http_protocol_options'][ key] == expected return True econf_foreach_hcm(econf, check, envoy_version=v)