Skip to content

Commit 8989051

Browse files
committed
Add support for s2i builds in httpd container
Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 438f2be commit 8989051

File tree

2 files changed

+62
-14
lines changed

2 files changed

+62
-14
lines changed

test/container/test_httpd.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
VERSION = os.getenv("VERSION")
1313
IMAGE_NAME = os.getenv("IMAGE_NAME")
14-
OS = os.getenv("TARGET")
14+
OS = os.getenv("OS")
1515

1616
image_name = os.environ.get("IMAGE_NAME").split(":")[0]
1717
image_tag = os.environ.get("IMAGE_NAME").split(":")[1]
@@ -26,11 +26,10 @@ def app(request):
2626
# app_name = os.path.basename(request.param)
2727
yield app
2828
pass
29-
#app.rmi()
29+
app.cleanup_container()
3030

3131

3232
class TestHttpdAppContainer:
33-
3433
def test_default_path(self, app):
3534
assert app.create_container(cid_file="test_default_page")
3635
cip = app.get_cip()
@@ -53,3 +52,22 @@ def test_run_as_root(self, app):
5352

5453
def test_run_s2i_usage(self, app):
5554
assert app.s2i_usage() != ""
55+
56+
@pytest.mark.parametrize(
57+
"dockerfile",
58+
[
59+
"Dockerfile",
60+
"Dockerfile.s2i"
61+
]
62+
)
63+
def test_dockerfiles(self, app, dockerfile):
64+
assert app.build_test_container(
65+
dockerfile=f"test/examples/{dockerfile}", app_url="https://github.com/sclorg/httpd-ex.git",
66+
app_dir="app-src"
67+
)
68+
assert app.test_run_app_dockerfile()
69+
cip = app.get_app_cip()
70+
assert cip
71+
assert app.test_response(url=f"{cip}", expected_code=200, expected_output="Welcome to your static httpd application on OpenShift")
72+
app.rmi_app()
73+

test/container/test_httpd_s2i.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
image_tag = os.environ.get("IMAGE_NAME").split(":")[1]
1919
test_dir = os.path.abspath(os.path.dirname(__file__))
2020
pre_init_test_app = os.path.join(test_dir, "..", "pre-init-test-app")
21+
self_cert_test = os.path.join(test_dir, "..", "self-signed-ssl")
22+
sample_test_app = os.path.join(test_dir, "..", "sample-test-app")
2123

22-
app_paths = [
23-
pre_init_test_app
24-
]
24+
app_params_pre = [pre_init_test_app]
25+
app_params_sample = [sample_test_app]
2526

2627

27-
@pytest.fixture(scope="module", params=app_paths)
28-
def s2i_app(request):
28+
@pytest.fixture(scope="module", params=app_params_pre)
29+
def s2i_app_pre_init(request):
2930
ci = S2IContainerImage(full_image_name)
3031
app_name = os.path.basename(request.param)
3132
s2i_app = ci.s2i_build_as_df(
@@ -40,14 +41,43 @@ def s2i_app(request):
4041
s2i_app.cleanup_container()
4142

4243

43-
class TestHttpdS2IContainer:
44+
@pytest.fixture(scope="module", params=app_params_sample)
45+
def s2i_sample_app(request):
46+
ci = S2IContainerImage(full_image_name)
47+
app_name = os.path.basename(request.param)
48+
s2i_app = ci.s2i_build_as_df(
49+
app_path=request.param,
50+
s2i_args="--pull-policy=never",
51+
src_image=full_image_name,
52+
dst_image=f"{full_image_name}-{app_name}"
53+
)
54+
yield s2i_app
55+
pass
56+
if s2i_app:
57+
s2i_app.cleanup_container()
58+
59+
60+
@pytest.mark.usefixtures("s2i_app_pre_init")
61+
class TestHttpdS2IPreInitContainer:
4462

45-
def test_run_pre_init_test(self, s2i_app):
63+
def test_run_pre_init_test(self, s2i_app_pre_init):
4664
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()
65+
assert s2i_app_pre_init
66+
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)
67+
cip = s2i_app_pre_init.get_cip()
5068
assert cip
5169
response = "This content was replaced by pre-init script."
52-
assert s2i_app.test_response(url=f"{cip}", expected_code=200, expected_output=response)
70+
assert s2i_app_pre_init.test_response(url=f"{cip}", expected_code=200, expected_output=response)
5371

72+
73+
@pytest.mark.usefixtures("s2i_sample_app")
74+
class TestHttpdS2ISampleAppContainer:
75+
76+
def test_self_cert_test(self, s2i_sample_app):
77+
print("run_pre_init_test")
78+
assert s2i_sample_app
79+
assert s2i_sample_app.create_container(cid_file="testing-sample=app", container_args="--user 1000", image_name=s2i_sample_app.image_name)
80+
cip = s2i_sample_app.get_cip()
81+
assert cip
82+
response = "This is a sample s2i application with static content."
83+
assert s2i_sample_app.test_response(url=f"{cip}", expected_code=200, expected_output=response)

0 commit comments

Comments
 (0)