Skip to content
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

First PoC for testing httpd-2.4 container by PyTest #234

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 2.4/test/container
1 change: 1 addition & 0 deletions 2.4/test/openshift
1 change: 0 additions & 1 deletion 2.4/test/test_httpd_ex_template.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4/test/test_httpd_imagestream_s2i.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4/test/test_httpd_imagestreams.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4/test/test_httpd_integration.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4/test/test_httpd_shared_helm_imagestreams.py

This file was deleted.

1 change: 0 additions & 1 deletion 2.4/test/test_httpd_shared_helm_template.py

This file was deleted.

73 changes: 73 additions & 0 deletions test/container/test_httpd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import os
import sys
import pytest

from container_ci_suite.engines.container import ContainerImage
from container_ci_suite.utils import check_variables

if not check_variables():
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
sys.exit(1)

VERSION = os.getenv("VERSION")
IMAGE_NAME = os.getenv("IMAGE_NAME")
OS = os.getenv("OS")

image_name = os.environ.get("IMAGE_NAME").split(":")[0]
image_tag = os.environ.get("IMAGE_NAME").split(":")[1]
test_dir = os.path.abspath(os.path.dirname(__file__))
print(f"Test dir is: {test_dir}")


@pytest.fixture(scope="module")
def app(request):
app = ContainerImage(image_name)
print(request)
# app_name = os.path.basename(request.param)
yield app
pass
app.cleanup_container()


class TestHttpdAppContainer:
def test_default_path(self, app):
assert app.create_container(cid_file="test_default_page")
cip = app.get_cip()
assert cip
if OS == "c9s" or OS == "c10s":
response = "HTTP Server Test Page"
else:
response = "Test Page for the HTTP Server on"
assert app.test_response(url=f"{cip}", expected_code=403, expected_output=response, max_tests=3)

def test_run_as_root(self, app):
assert app.create_container(cid_file="test_default_page", container_args="--user 0")
cip = app.get_cip()
assert cip
if OS == "c9s" or OS == "c10s":
response = "HTTP Server Test Page"
else:
response = "Test Page for the HTTP Server on"
assert app.test_response(url=f"{cip}", expected_code=403, expected_output=response, max_tests=3)

def test_run_s2i_usage(self, app):
assert app.s2i_usage() != ""

@pytest.mark.parametrize(
"dockerfile",
[
"Dockerfile",
"Dockerfile.s2i"
]
)
def test_dockerfiles(self, app, dockerfile):
assert app.build_test_container(
dockerfile=f"test/examples/{dockerfile}", app_url="https://github.com/sclorg/httpd-ex.git",
app_dir="app-src"
)
assert app.test_run_app_dockerfile()
cip = app.get_app_cip()
assert cip
assert app.test_response(url=f"{cip}", expected_code=200, expected_output="Welcome to your static httpd application on OpenShift")
app.rmi_app()

83 changes: 83 additions & 0 deletions test/container/test_httpd_s2i.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import os
import sys
import pytest

from container_ci_suite.engines.s2i_container import S2IContainerImage
from container_ci_suite.utils import check_variables

if not check_variables():
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
sys.exit(1)

VERSION = os.getenv("VERSION")
IMAGE_NAME = os.getenv("IMAGE_NAME")
OS = os.getenv("TARGET")

full_image_name = os.environ.get("IMAGE_NAME")
image_tag_wo_tag = os.environ.get("IMAGE_NAME").split(":")[0]
image_tag = os.environ.get("IMAGE_NAME").split(":")[1]
test_dir = os.path.abspath(os.path.dirname(__file__))
pre_init_test_app = os.path.join(test_dir, "..", "pre-init-test-app")
self_cert_test = os.path.join(test_dir, "..", "self-signed-ssl")
sample_test_app = os.path.join(test_dir, "..", "sample-test-app")

app_params_pre = [pre_init_test_app]
app_params_sample = [sample_test_app]


@pytest.fixture(scope="module", params=app_params_pre)
def s2i_app_pre_init(request):
ci = S2IContainerImage(full_image_name)
app_name = os.path.basename(request.param)
s2i_app = ci.s2i_build_as_df(
app_path=request.param,
s2i_args="--pull-policy=never",
src_image=full_image_name,
dst_image=f"{full_image_name}-{app_name}"
)
yield s2i_app
pass
if s2i_app:
s2i_app.cleanup_container()


@pytest.fixture(scope="module", params=app_params_sample)
def s2i_sample_app(request):
ci = S2IContainerImage(full_image_name)
app_name = os.path.basename(request.param)
s2i_app = ci.s2i_build_as_df(
app_path=request.param,
s2i_args="--pull-policy=never",
src_image=full_image_name,
dst_image=f"{full_image_name}-{app_name}"
)
yield s2i_app
pass
if s2i_app:
s2i_app.cleanup_container()


@pytest.mark.usefixtures("s2i_app_pre_init")
class TestHttpdS2IPreInitContainer:

def test_run_pre_init_test(self, s2i_app_pre_init):
print("run_pre_init_test")
assert s2i_app_pre_init
assert s2i_app_pre_init.create_container(cid_file="testing-app-pre-init", container_args="--user 1000", image_name=s2i_app_pre_init.image_name)
cip = s2i_app_pre_init.get_cip()
assert cip
response = "This content was replaced by pre-init script."
assert s2i_app_pre_init.test_response(url=f"{cip}", expected_code=200, expected_output=response)


@pytest.mark.usefixtures("s2i_sample_app")
class TestHttpdS2ISampleAppContainer:

def test_self_cert_test(self, s2i_sample_app):
print("run_pre_init_test")
assert s2i_sample_app
assert s2i_sample_app.create_container(cid_file="testing-sample=app", container_args="--user 1000", image_name=s2i_sample_app.image_name)
cip = s2i_sample_app.get_cip()
assert cip
response = "This is a sample s2i application with static content."
assert s2i_sample_app.test_response(url=f"{cip}", expected_code=200, expected_output=response)
Loading