Skip to content

Commit

Permalink
Add tests for health-status and nginx-debug cli args
Browse files Browse the repository at this point in the history
  • Loading branch information
tellet committed Jan 10, 2020
1 parent 94c326b commit b54aca6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tests/suite/resources_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,17 +918,18 @@ def delete_items_from_yaml(kube_apis, yaml_manifest, namespace) -> None:
delete_configmap(kube_apis.v1, doc['metadata']['name'], namespace)


def ensure_connection(request_url) -> None:
def ensure_connection(request_url, expected_code=404) -> None:
"""
Wait for connection.
:param request_url: url to request
:param expected_code: response code
:return:
"""
for _ in range(4):
try:
resp = requests.get(request_url, verify=False)
if resp.status_code == 404:
if resp.status_code == expected_code:
return
except Exception as ex:
print(f"Warning: there was an exception {str(ex)}")
Expand Down
29 changes: 29 additions & 0 deletions tests/suite/test_healthcheck_uri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest
import requests

from suite.resources_utils import ensure_connection


@pytest.mark.ingresses
@pytest.mark.parametrize('ingress_controller, expected_responses',
[
pytest.param({"extra_args": ["-health-status=true",
"-health-status-uri=/something-va(l)id/blabla"]},
{"/something-va(l)id/blabla": 200, "/nginx-health": 404},
id="custom-health-status-uri"),
pytest.param({"extra_args": ["-health-status=true"]},
{"/something-va(l)id/blabla": 404, "/nginx-health": 200},
id="default-health-status-uri"),
pytest.param({"extra_args": ["-health-status=false"]},
{"/something-va(l)id/blabla": 404, "/nginx-health": 404},
id="disable-health-status")
],
indirect=["ingress_controller"])
class TestHealthStatusURI:
def test_response_code(self, ingress_controller_endpoint, ingress_controller, expected_responses):
for uri in expected_responses:
req_url = f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.port}{uri}"
ensure_connection(req_url, expected_responses[uri])
resp = requests.get(req_url)
assert resp.status_code == expected_responses[uri],\
f"Expected {expected_responses[uri]} code for {uri} but got {resp.status_code}"
8 changes: 7 additions & 1 deletion tests/suite/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ def fin():

@pytest.mark.ingresses
@pytest.mark.smoke
@pytest.mark.parametrize('ingress_controller',
[
pytest.param({"extra_args": None}, id="no-additional-cli-args"),
pytest.param({"extra_args": ["-nginx-debug", "-health-status=true"]},
id="some-additional-cli-args")
], indirect=True)
class TestSmoke:
@pytest.mark.parametrize("path", paths)
def test_response_code_200_and_server_name(self, smoke_setup, path):
def test_response_code_200_and_server_name(self, ingress_controller, smoke_setup, path):
req_url = f"https://{smoke_setup.public_endpoint.public_ip}:{smoke_setup.public_endpoint.port_ssl}/{path}"
ensure_response_from_backend(req_url, smoke_setup.ingress_host)
resp = requests.get(req_url, headers={"host": smoke_setup.ingress_host}, verify=False)
Expand Down

0 comments on commit b54aca6

Please sign in to comment.