Skip to content

Commit

Permalink
Update python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pleshakov committed Sep 27, 2021
1 parent 8606b37 commit 470174e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
10 changes: 7 additions & 3 deletions tests/suite/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def fin():
@pytest.mark.ingresses
@pytest.mark.parametrize('annotations_setup', ["standard", "mergeable"], indirect=True)
class TestAnnotations:
def test_nginx_config_defaults(self, kube_apis, annotations_setup, ingress_controller_prerequisites):
def test_nginx_config_defaults(self, kube_apis, annotations_setup, ingress_controller_prerequisites, cli_arguments):
print("Case 1: no ConfigMap keys, no annotations in Ingress")
result_conf = get_ingress_nginx_template_conf(kube_apis.v1,
annotations_setup.namespace,
Expand All @@ -178,8 +178,12 @@ def test_nginx_config_defaults(self, kube_apis, annotations_setup, ingress_contr

assert "Strict-Transport-Security" not in result_conf

expected_zone_size = "256k"
if cli_arguments["ic-type"] == "nginx-plus-ingress":
expected_zone_size = "512k"

for upstream in annotations_setup.upstream_names:
assert f"zone {upstream} 256k;" in result_conf
assert f"zone {upstream} {expected_zone_size};" in result_conf

@pytest.mark.parametrize('annotations, expected_strings, unexpected_strings', [
({"nginx.org/proxy-send-timeout": "10s", "nginx.org/max-conns": "1024",
Expand Down Expand Up @@ -318,7 +322,7 @@ def test_upstream_zone_size_0(self, cli_arguments, kube_apis,
if cli_arguments["ic-type"] == "nginx-plus-ingress":
print("Run assertions for Nginx Plus case")
assert "zone " in result_conf
assert " 256k;" in result_conf
assert " 512k;" in result_conf
elif cli_arguments["ic-type"] == "nginx-ingress":
print("Run assertions for Nginx OSS case")
assert "zone " not in result_conf
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/test_externalname_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_ic_template_config_upstream_zone(self, kube_apis, ingress_controller_pr
ingress_controller_prerequisites.namespace)
line = f"zone {external_name_setup.namespace}-" \
f"{external_name_setup.ingress_name}-" \
f"{external_name_setup.ingress_host}-{external_name_setup.service}-80 256k;"
f"{external_name_setup.ingress_host}-{external_name_setup.service}-80 512k;"
assert line in result_conf

def test_ic_template_config_upstream_rule(self, kube_apis, ingress_controller_prerequisites,
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/test_v_s_route_externalname.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_template_config(self, kube_apis,
ingress_controller_prerequisites.namespace)

line = f"zone vs_{vsr_externalname_setup.namespace}_{vsr_externalname_setup.vs_name}" \
f"_vsr_{vsr_externalname_setup.route.namespace}_{vsr_externalname_setup.route.name}_ext-backend 256k;"
f"_vsr_{vsr_externalname_setup.route.namespace}_{vsr_externalname_setup.route.name}_ext-backend 512k;"
assert line in initial_config
assert "random two least_conn;" in initial_config
assert f"server {vsr_externalname_setup.external_host}:80 max_fails=1 fail_timeout=10s max_conns=0 resolve;"\
Expand Down
17 changes: 13 additions & 4 deletions tests/suite/test_virtual_server_configmap_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def assert_specific_keys_for_nginx_plus(config, expected_values):
assert f"server_tokens \"{expected_values['server-tokens']}\";" in config
assert "random two least_conn;" not in config \
and expected_values['lb-method'] in config
assert "zone " in config and " 256k;" in config
assert "zone " in config and " 512k;" in config


def assert_specific_keys_for_nginx_oss(config, expected_values):
Expand All @@ -79,8 +79,15 @@ def assert_specific_keys_for_nginx_oss(config, expected_values):
and expected_values['lb-method'] in config
assert "zone " not in config and " 256k;" not in config

def assert_defaults_of_keys_with_validation_for_nginx_plus(config, unexpected_values):
assert_common_defaults_of_keys_with_validation(config, unexpected_values)
assert "zone " in config and " 512k;" in config

def assert_defaults_of_keys_with_validation_for_nginx_oss(config, unexpected_values):
assert_common_defaults_of_keys_with_validation(config, unexpected_values)
assert "zone " in config and " 256k;" in config

def assert_defaults_of_keys_with_validation(config, unexpected_values):
def assert_common_defaults_of_keys_with_validation(config, unexpected_values):
assert "proxy_buffering on;" in config
assert "real_ip_recursive" not in config
assert "max_fails=1" in config
Expand All @@ -89,7 +96,6 @@ def assert_defaults_of_keys_with_validation(config, unexpected_values):
assert "server_tokens \"on\"" in config
assert "random two least_conn;" in config and unexpected_values['lb-method'] not in config
assert f"proxy_send_timeout 60s;" in config
assert "zone " in config and " 256k;" in config


def assert_defaults_of_keys_with_validation_in_main_config(config, unexpected_values):
Expand Down Expand Up @@ -222,7 +228,10 @@ def test_keys(self, cli_arguments, kube_apis, ingress_controller_prerequisites,
ingress_controller_prerequisites.namespace)
step_4_events = get_events(kube_apis.v1, virtual_server_setup.namespace)
assert_update_event_count_increased(virtual_server_setup, step_4_events, step_3_events)
assert_defaults_of_keys_with_validation(step_4_config, expected_values)
if cli_arguments['ic-type'] == "nginx-ingress":
assert_defaults_of_keys_with_validation_for_nginx_oss(step_4_config, expected_values)
else:
assert_defaults_of_keys_with_validation_for_nginx_plus(step_4_config, expected_values)

def test_keys_in_main_config(self, cli_arguments, kube_apis, ingress_controller_prerequisites,
crd_ingress_controller, virtual_server_setup, clean_up):
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/test_virtual_server_external_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_template_config(self, kube_apis, ingress_controller_prerequisites,
virtual_server_setup.vs_name,
vs_externalname_setup.ic_pod_name,
ingress_controller_prerequisites.namespace)
line = f"zone vs_{virtual_server_setup.namespace}_{virtual_server_setup.vs_name}_backend1 256k;"
line = f"zone vs_{virtual_server_setup.namespace}_{virtual_server_setup.vs_name}_backend1 512k;"
assert line in result_conf
assert "random two least_conn;" in result_conf
assert f"server {vs_externalname_setup.external_host}:80 max_fails=1 fail_timeout=10s max_conns=0 resolve;"\
Expand Down

0 comments on commit 470174e

Please sign in to comment.