-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First PoC for testing httpd-2.4 container by PyTest
Signed-off-by: Petr "Stone" Hracek <[email protected]>
- Loading branch information
Showing
10 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../test/container/test_httpd.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../test/container/test_httpd_s2i.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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("TARGET") | ||
|
||
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.rmi() | ||
|
||
|
||
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() != "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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") | ||
|
||
app_paths = [ | ||
pre_init_test_app | ||
] | ||
|
||
|
||
@pytest.fixture(scope="module", params=app_paths) | ||
def s2i_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() | ||
|
||
|
||
class TestHttpdS2IContainer: | ||
|
||
def test_run_pre_init_test(self, s2i_app): | ||
print("run_pre_init_test") | ||
assert s2i_app | ||
assert s2i_app.create_container(cid_file="testing-app-pre-init", container_args="--user 1000") | ||
cip = s2i_app.get_cip() | ||
assert cip | ||
response = "This content was replaced by pre-init script." | ||
assert s2i_app.test_response(url=f"{cip}", expected_code=200, expected_output=response) | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.