Skip to content

Commit 32327e8

Browse files
committed
Add more documentation descriptions to each test suite
Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
1 parent 8b2045c commit 32327e8

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

test/test_container_application.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ def teardown_method(self):
3636
"--user 12345"
3737
]
3838
)
39-
# test_application
4039
def test_application(self, container_arg):
40+
"""
41+
Test if container works under specific user
42+
and not only with user --user 10001
43+
"""
4144
version = VERSION.replace("-micro", "")
4245
cid_file_name = "test-app"
4346
assert self.app.create_container(
@@ -46,20 +49,25 @@ def test_application(self, container_arg):
4649
)
4750
cip = self.app.get_cip(cid_file_name=cid_file_name)
4851
assert cip
52+
# nginx -v returns proper version
4953
assert PodmanCLIWrapper.podman_run_command(
5054
f"--rm {self.app.image_name} /bin/bash -c 'nginx -v'"
5155
).startswith(f"nginx version: nginx/{version}")
56+
# Response code from HTTP url is 200 and contains proper output
5257
assert self.app.test_response(
5358
url=f"http://{cip}", expected_output="NGINX is working"
5459
)
60+
# Response code from HTTP url is 200 and contains proper output
5561
assert self.app.test_response(
5662
url=f"http://{cip}", expected_output="NGINX2 is working",
5763
host="localhost2"
5864
)
65+
# Response code from HTTP url is 200 and contains proper output
5966
assert self.app.test_response(
6067
url=f"http://{cip}", expected_output="NGINX2 is working",
6168
page="/aliased/index2.html"
6269
)
70+
# Response code from HTTP url is 404 and nginx-cfg/default.conf is not accessible
6371
assert self.app.test_response(
6472
url=f"http://{cip}", expected_code=404,
6573
page="/nginx-cfg/default.conf"

test/test_container_basics.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,25 @@ def teardown_method(self):
1616
self.app.cleanup()
1717

1818
def test_run_s2i_usage(self, app):
19+
"""
20+
Test if s2i usage works
21+
"""
1922
output = app.s2i_usage()
2023
assert output != ""
2124

2225
def test_docker_run_usage(self):
26+
"""
27+
Test if container is runnable
28+
"""
2329
assert PodmanCLIWrapper.call_podman_command(
2430
cmd=f"run --rm {IMAGE_NAME} &>/dev/null",
2531
return_output=False
2632
) == 0
2733

2834
def test_scl_usage(self):
35+
"""
36+
Test if nginx -v returns proper output
37+
"""
2938
version = VERSION.replace("-micro", "")
3039
assert PodmanCLIWrapper.podman_run_command(
3140
f"--rm {IMAGE_NAME} /bin/bash -c 'nginx -v'"
@@ -39,6 +48,10 @@ def test_scl_usage(self):
3948
]
4049
)
4150
def test_dockerfiles(self, app, dockerfile):
51+
"""
52+
Test if building nginx-container based on
53+
examples/Dockerfile works
54+
"""
4255
version = VERSION.replace("-micro", "")
4356
dp = DockerfileProcessor(dockerfile_path=f"{TEST_DIR}/examples/{dockerfile}")
4457
dp.update_env_in_dockerfile(version=version, what_to_replace="ENV NGINX_VERSION")
@@ -52,5 +65,4 @@ def test_dockerfiles(self, app, dockerfile):
5265
assert app.test_app_dockerfile()
5366
cip = app.get_cip()
5467
assert cip
55-
assert app.test_response(url=cip, expected_code=200,
56-
expected_output="NGINX is working")
68+
assert app.test_response(url=cip, expected_output="NGINX is working")

test/test_container_example_apps.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616

1717
def build_s2i_app(app_path: Path) -> ContainerTestLib:
18+
"""
19+
Build S2I Container based on the app_path input
20+
:param: app_path: path to example directory
21+
:return new instance of ContainerTestLib
22+
"""
1823
container_lib = ContainerTestLib(IMAGE_NAME)
1924
app_name = app_path.name
2025
s2i_app = container_lib.build_as_df(
@@ -38,7 +43,9 @@ def teardown_method(self):
3843
def test_run_app_test(self, example_app_test):
3944
version = VERSION.replace("-micro", "")
4045
cid_file_name = example_app_test.app_name
46+
# Create container with --user 10001
4147
assert self.s2i_app.create_container(cid_file_name=cid_file_name, container_args="--user 10001")
48+
# Wait till container does not start
4249
assert ContainerImage.wait_for_cid(cid_file_name=cid_file_name)
4350
cid = self.s2i_app.get_cid(cid_file_name=cid_file_name)
4451
assert cid
@@ -47,7 +54,9 @@ def test_run_app_test(self, example_app_test):
4754
command = PodmanCLIWrapper.podman_get_file_content(
4855
cid_file_name=cid, filename="/opt/app-root/etc/nginx.d/default.conf"
4956
)
57+
# Checks if nginx configuration contains resolver
5058
assert re.search("resolver", command)
59+
# Checks if nginx configuration DO NOT container "DNS_SERVER"
5160
assert not re.search("DNS_SERVER", command)
5261
assert PodmanCLIWrapper.podman_run_command(
5362
f"--rm {example_app_test.image_name} /bin/bash -c 'nginx -v'"
@@ -83,6 +92,7 @@ def test_run_app_test(self):
8392
assert cid
8493
cip = self.s2i_app.get_cip(cid_file_name=cid_file_name)
8594
assert cip
95+
# Checks if returns header of Perl version
8696
perl_version = PodmanCLIWrapper.podman_exec_shell_command(cid_file_name=cid, cmd="perl -e 'print \"$^V\"'")
8797
assert self.s2i_app.test_response(
8898
url=f"http://{cip}", port=8080,
@@ -115,14 +125,15 @@ def test_log_output(self, s2i_log_test):
115125
url=f"http://{cip}", port=8080, expected_output="NGINX is working"
116126
)
117127
assert '"GET / HTTP/1.1" 200' in s2i_log_test.get_logs(cid_file_name=cid_file_name)
128+
# Check if /nothing-at-all is really no accessible
118129
assert self.s2i_app.test_response(
119130
url=f"http://{cip}", port=8080, page="/nothing-at-all", expected_code=404
120131
)
121132
logs = self.s2i_app.get_logs(cid_file_name=cid_file_name)
122133
assert logs
134+
# Checks logs container 'failed' and 'No such file or directory'
123135
assert re.search("open.*failed.*No such file or directory", logs)
124136

125-
# test_log_volume_output
126137
def test_log_volume_output(self, s2i_log_test):
127138
cid_file_name = "test-app"
128139
s2i_log_test.set_new_image(image_name=f"{IMAGE_NAME}-{cid_file_name}")
@@ -138,9 +149,11 @@ def test_log_volume_output(self, s2i_log_test):
138149
cid_file_name=cid,
139150
filename="/var/log/nginx/access.log"
140151
)
152+
# Check if /nothing-at-all is really no accessible
141153
assert self.s2i_app.test_response(
142154
url=f"http://{cip}", port=8080, page="/nothing-at-all", expected_code=404
143155
)
156+
# Check if /nothing-at-all is really mentioned in 'access.log'
144157
assert '"GET /nothing-at-all HTTP/1.1" 404' in PodmanCLIWrapper.podman_get_file_content(
145158
cid_file_name=cid,
146159
filename="/var/log/nginx/access.log"
@@ -149,5 +162,6 @@ def test_log_volume_output(self, s2i_log_test):
149162
cid_file_name=cid,
150163
filename="/var/log/nginx/error.log"
151164
)
165+
# Checks logs container 'failed' and 'No such file or directory'
152166
assert re.search("open.*failed.*No such file or directory", logs_to_check)
153167

0 commit comments

Comments
 (0)