github.com/nginxinc/kubernetes-ingress@v1.12.5/tests/suite/test_smoke.py (about)

     1  import requests
     2  import pytest
     3  
     4  from suite.fixtures import PublicEndpoint
     5  from suite.resources_utils import create_secret_from_yaml, delete_secret, \
     6      ensure_connection_to_public_endpoint, create_items_from_yaml, \
     7      delete_items_from_yaml, create_example_app, delete_common_app, \
     8      wait_until_all_pods_are_ready, ensure_response_from_backend
     9  from suite.yaml_utils import get_first_ingress_host_from_yaml
    10  from settings import TEST_DATA
    11  
    12  paths = ["backend1", "backend2"]
    13  
    14  
    15  class SmokeSetup:
    16      """
    17      Encapsulate the Smoke Example details.
    18  
    19      Attributes:
    20          public_endpoint (PublicEndpoint):
    21          ingress_host (str):
    22      """
    23      def __init__(self, public_endpoint: PublicEndpoint, ingress_host):
    24          self.public_endpoint = public_endpoint
    25          self.ingress_host = ingress_host
    26  
    27  
    28  @pytest.fixture(scope="class", params=["standard", "mergeable"])
    29  def smoke_setup(request, kube_apis, ingress_controller_endpoint, ingress_controller, test_namespace) -> SmokeSetup:
    30      print("------------------------- Deploy Smoke Example -----------------------------------")
    31      secret_name = create_secret_from_yaml(kube_apis.v1, test_namespace, f"{TEST_DATA}/smoke/smoke-secret.yaml")
    32      create_items_from_yaml(kube_apis, f"{TEST_DATA}/smoke/{request.param}/smoke-ingress.yaml", test_namespace)
    33      ingress_host = get_first_ingress_host_from_yaml(f"{TEST_DATA}/smoke/{request.param}/smoke-ingress.yaml")
    34      create_example_app(kube_apis, "simple", test_namespace)
    35      wait_until_all_pods_are_ready(kube_apis.v1, test_namespace)
    36      ensure_connection_to_public_endpoint(ingress_controller_endpoint.public_ip,
    37                                           ingress_controller_endpoint.port,
    38                                           ingress_controller_endpoint.port_ssl)
    39  
    40      def fin():
    41          print("Clean up the Smoke Application:")
    42          delete_common_app(kube_apis, "simple", test_namespace)
    43          delete_items_from_yaml(kube_apis, f"{TEST_DATA}/smoke/{request.param}/smoke-ingress.yaml",
    44                                 test_namespace)
    45          delete_secret(kube_apis.v1, secret_name, test_namespace)
    46  
    47      request.addfinalizer(fin)
    48  
    49      return SmokeSetup(ingress_controller_endpoint, ingress_host)
    50  
    51  
    52  @pytest.mark.ingresses
    53  @pytest.mark.smoke
    54  @pytest.mark.parametrize('ingress_controller',
    55                           [
    56                               pytest.param({"extra_args": None}, id="no-additional-cli-args"),
    57                               pytest.param({"extra_args": ["-nginx-debug", "-health-status=true"]},
    58                                            id="some-additional-cli-args")
    59                           ], indirect=True)
    60  class TestSmoke:
    61      @pytest.mark.parametrize("path", paths)
    62      def test_response_code_200_and_server_name(self, ingress_controller, smoke_setup, path):
    63          req_url = f"https://{smoke_setup.public_endpoint.public_ip}:{smoke_setup.public_endpoint.port_ssl}/{path}"
    64          ensure_response_from_backend(req_url, smoke_setup.ingress_host)
    65          resp = requests.get(req_url, headers={"host": smoke_setup.ingress_host}, verify=False)
    66          assert resp.status_code == 200
    67          assert f"Server name: {path}" in resp.text