Skip to content

Commit 644d4c9

Browse files
committed
First PoC for testing httpd-2.4 container by PyTest
Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 4d23848 commit 644d4c9

10 files changed

+110
-0
lines changed

2.4/test/container/test_httpd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../test/container/test_httpd.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../test/container/test_httpd_s2i.py

test/container/test_httpd.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
import sys
3+
import pytest
4+
5+
from container_ci_suite.engines.container import ContainerImage
6+
from container_ci_suite.utils import check_variables
7+
8+
if not check_variables():
9+
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
10+
sys.exit(1)
11+
12+
VERSION = os.getenv("VERSION")
13+
IMAGE_NAME = os.getenv("IMAGE_NAME")
14+
OS = os.getenv("TARGET")
15+
16+
image_name = os.environ.get("IMAGE_NAME").split(":")[0]
17+
image_tag = os.environ.get("IMAGE_NAME").split(":")[1]
18+
test_dir = os.path.abspath(os.path.dirname(__file__))
19+
print(f"Test dir is: {test_dir}")
20+
21+
22+
@pytest.fixture(scope="module")
23+
def app(request):
24+
app = ContainerImage(image_name)
25+
print(request)
26+
# app_name = os.path.basename(request.param)
27+
yield app
28+
pass
29+
#app.rmi()
30+
31+
32+
class TestHttpdAppContainer:
33+
34+
def test_default_path(self, app):
35+
assert app.create_container(cid_file="test_default_page")
36+
cip = app.get_cip()
37+
assert cip
38+
if OS == "c9s" or OS == "c10s":
39+
response = "HTTP Server Test Page"
40+
else:
41+
response = "Test Page for the HTTP Server on"
42+
assert app.test_response(url=f"{cip}", expected_code=403, expected_output=response, max_tests=3)
43+
44+
def test_run_as_root(self, app):
45+
assert app.create_container(cid_file="test_default_page", container_args="--user 0")
46+
cip = app.get_cip()
47+
assert cip
48+
if OS == "c9s" or OS == "c10s":
49+
response = "HTTP Server Test Page"
50+
else:
51+
response = "Test Page for the HTTP Server on"
52+
assert app.test_response(url=f"{cip}", expected_code=403, expected_output=response, max_tests=3)
53+
54+
def test_run_s2i_usage(self, app):
55+
assert app.s2i_usage() != ""

test/container/test_httpd_s2i.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
import sys
3+
import pytest
4+
5+
from container_ci_suite.engines.s2i_container import S2IContainerImage
6+
from container_ci_suite.utils import check_variables
7+
8+
if not check_variables():
9+
print("At least one variable from IMAGE_NAME, OS, VERSION is missing.")
10+
sys.exit(1)
11+
12+
VERSION = os.getenv("VERSION")
13+
IMAGE_NAME = os.getenv("IMAGE_NAME")
14+
OS = os.getenv("TARGET")
15+
16+
full_image_name = os.environ.get("IMAGE_NAME")
17+
image_tag_wo_tag = os.environ.get("IMAGE_NAME").split(":")[0]
18+
image_tag = os.environ.get("IMAGE_NAME").split(":")[1]
19+
test_dir = os.path.abspath(os.path.dirname(__file__))
20+
pre_init_test_app = os.path.join(test_dir, "..", "pre-init-test-app")
21+
22+
app_paths = [
23+
pre_init_test_app
24+
]
25+
26+
27+
@pytest.fixture(scope="module", params=app_paths)
28+
def s2i_app(request):
29+
ci = S2IContainerImage(full_image_name)
30+
app_name = os.path.basename(request.param)
31+
s2i_app = ci.s2i_build_as_df(
32+
app_path=request.param,
33+
s2i_args="--pull-policy=never",
34+
src_image=full_image_name,
35+
dst_image=f"{full_image_name}-{app_name}"
36+
)
37+
yield s2i_app
38+
pass
39+
if s2i_app:
40+
s2i_app.cleanup_container()
41+
42+
43+
class TestHttpdS2IContainer:
44+
45+
def test_run_pre_init_test(self, s2i_app):
46+
print("run_pre_init_test")
47+
assert s2i_app
48+
assert s2i_app.create_container(cid_file="testing-app-pre-init", container_args="--user 1000")
49+
cip = s2i_app.get_cip()
50+
assert cip
51+
response = "This content was replaced by pre-init script."
52+
assert s2i_app.test_response(url=f"{cip}", expected_code=200, expected_output=response)
53+
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)