-
Notifications
You must be signed in to change notification settings - Fork 198
Container PyTest for Nginx-container #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ab047d5
1223c90
7b672c4
b68222a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/conftest.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/run-pytest |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_application.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_basics.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_example_apps.py |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestream_s2i.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_local_example.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_remote_example.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_template.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_template_example_app.py |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/conftest.py |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/run-pytest |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_application.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_basics.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_example_apps.py |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestream_s2i.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_local_example.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_remote_example.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_template.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_template_example_app.py |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/conftest.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/run-pytest |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_application.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_basics.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_example_apps.py |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestream_s2i.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_local_example.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_remote_example.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_template.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_template_example_app.py |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/conftest.py |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/run-pytest |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_application.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_basics.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_container_example_apps.py |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestream_s2i.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_local_example.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_remote_example.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_imagestreams.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_shared_helm_template.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../test/test_ocp_template_example_app.py |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| from pathlib import Path | ||
| from collections import namedtuple | ||
| from pytest import skip | ||
|
|
||
| from container_ci_suite.utils import check_variables | ||
|
|
||
| if not check_variables(): | ||
| sys.exit(1) | ||
|
|
||
| TAGS = { | ||
| "rhel8": "-ubi8", | ||
| "rhel9": "-ubi9", | ||
| "rhel10": "-ubi10", | ||
| } | ||
|
|
||
| Vars = namedtuple( | ||
| "Vars", [ | ||
| "OS", "TAG", "VERSION", "IMAGE_NAME", "VERSION_NO_MICRO", "SHORT_VERSION", "TEST_DIR" | ||
| ] | ||
| ) | ||
| OS = os.getenv("TARGET").lower() | ||
| VERSION = os.getenv("VERSION") | ||
| BRANCH_TO_TEST = "master" | ||
|
|
||
| VARS = Vars( | ||
| OS=OS, | ||
| TAG=TAGS.get(OS), | ||
| VERSION=VERSION, | ||
| IMAGE_NAME=os.getenv("IMAGE_NAME"), | ||
| VERSION_NO_MICRO=VERSION.replace("-micro", ""), | ||
| SHORT_VERSION=VERSION.replace("-micro", "").replace(".", ""), | ||
| TEST_DIR=Path(__file__).parent.absolute(), | ||
| ) | ||
|
|
||
|
|
||
| def skip_clear_env_tests(): | ||
| if VARS.OS == "rhel8" and VERSION == "8.2": | ||
| skip(f"Skipping clear env tests for {VARS.VERSION} on {VARS.OS}.") |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/bash | ||
| # | ||
| # IMAGE_NAME specifies a name of the candidate image used for testing. | ||
| # The image has to be available before this script is executed. | ||
| # SINGLE_VERSION specifies the major version of the MariaDB in format of X.Y | ||
| # OS specifies RHEL version (e.g. OS=rhel8) | ||
| # | ||
|
|
||
| THISDIR=$(dirname ${BASH_SOURCE[0]}) | ||
|
|
||
| git show -s | ||
|
|
||
| PYTHON_VERSION="3.12" | ||
| if [[ ! -f "/usr/bin/python$PYTHON_VERSION" ]]; then | ||
| PYTHON_VERSION="3.13" | ||
| fi | ||
| cd "${THISDIR}" && "python${PYTHON_VERSION}" -m pytest -s -rA --showlocals -vv test_container_*.py | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| from pathlib import Path | ||
| from container_ci_suite.container_lib import ContainerTestLib | ||
| from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper | ||
| from conftest import VARS | ||
|
|
||
| test_app = VARS.TEST_DIR / "test-app" | ||
|
|
||
|
|
||
| def build_s2i_app(app_path: Path) -> ContainerTestLib: | ||
| container_lib = ContainerTestLib(VARS.IMAGE_NAME) | ||
| app_name = app_path.name | ||
| s2i_app = container_lib.build_as_df( | ||
| app_path=app_path, | ||
| s2i_args="--pull-policy=never", | ||
| src_image=VARS.IMAGE_NAME, | ||
| dst_image=f"{VARS.IMAGE_NAME}-{app_name}" | ||
| ) | ||
| return s2i_app | ||
|
|
||
|
|
||
| class TestNginxApplicationContainer: | ||
|
|
||
| def setup_method(self): | ||
| self.s2i_app = build_s2i_app(app_path=test_app) | ||
|
|
||
| def teardown_method(self): | ||
| self.s2i_app.cleanup() | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "container_arg", | ||
| [ | ||
| "", | ||
| "--user 12345" | ||
| ] | ||
| ) | ||
| def test_application(self, container_arg): | ||
| """ | ||
| Test if container works under specific user | ||
| and not only with user --user 10001 | ||
| """ | ||
| cid_file_name = "test-app" | ||
| assert self.s2i_app.create_container( | ||
| cid_file_name=cid_file_name, | ||
| container_args=f"--user 10001 {container_arg}" | ||
| ) | ||
| cip = self.s2i_app.get_cip(cid_file_name=cid_file_name) | ||
| assert cip | ||
| # nginx -v returns proper version | ||
| assert f"nginx/{VARS.VERSION_NO_MICRO}" in PodmanCLIWrapper.podman_run_command_and_remove( | ||
| cid_file_name=f"{VARS.IMAGE_NAME}-{cid_file_name}", | ||
| cmd="nginx -v" | ||
| ) | ||
| # Response code from HTTP url is 200 and contains proper output | ||
| assert self.s2i_app.test_response( | ||
| url=f"http://{cip}", expected_output="NGINX is working" | ||
| ) | ||
| # Response code from HTTP url is 200 and contains proper output | ||
| assert self.s2i_app.test_response( | ||
| url=f"http://{cip}", expected_output="NGINX2 is working", | ||
| host="localhost2" | ||
| ) | ||
| # Response code from HTTP url is 200 and contains proper output | ||
| assert self.s2i_app.test_response( | ||
| url=f"http://{cip}", expected_output="NGINX2 is working", | ||
| page="/aliased/index2.html" | ||
| ) | ||
| # Response code from HTTP url is 404 and nginx-cfg/default.conf is not accessible | ||
| assert self.s2i_app.test_response( | ||
| url=f"http://{cip}", expected_code=404, | ||
| page="/nginx-cfg/default.conf" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this is good for. The information about the last commit is usually available in the CI, and you typically don't need it in the output.