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

Add support for testing Helm Charts in PHP container. #464

Merged
merged 2 commits into from
Sep 11, 2024
Merged
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 7.4/test/test_helm_cakephp_application.py
1 change: 1 addition & 0 deletions 7.4/test/test_helm_chart_imagestreams.py
1 change: 1 addition & 0 deletions 8.0/test/test_helm_cakephp_application.py
1 change: 1 addition & 0 deletions 8.0/test/test_helm_chart_imagestreams.py
1 change: 1 addition & 0 deletions 8.1/test/test_helm_cakephp_application.py
1 change: 1 addition & 0 deletions 8.1/test/test_helm_chart_imagestreams.py
1 change: 1 addition & 0 deletions 8.2/test/test_helm_cakephp_application.py
1 change: 1 addition & 0 deletions 8.2/test/test_helm_chart_imagestreams.py
1 change: 1 addition & 0 deletions 8.3/test/test_helm_cakephp_application.py
1 change: 1 addition & 0 deletions 8.3/test/test_helm_chart_imagestreams.py
83 changes: 83 additions & 0 deletions test/test_helm_cakephp_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import os
import sys

import pytest
from pathlib import Path

from container_ci_suite.helm import HelmChartsAPI
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)


test_dir = Path(os.path.abspath(os.path.dirname(__file__)))


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

if VERSION == "7.4" or VERSION == "8.0":
check_msg = "Welcome to CakePHP 4.5"
elif VERSION == "8.1" or VERSION == "8.2" or VERSION == "8.3":
check_msg = "Welcome to CakePHP 4.5"
else:
check_msg = "Welcome to your CakePHP application on OpenShift"

TAGS = {
"rhel8": "-ubi8",
"rhel9": "-ubi9"
}
TAG = TAGS.get(OS, None)


class TestHelmCakePHPTemplate:

def setup_method(self):
package_name = "php-cakephp-application"
path = test_dir
self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, remote=True)
self.hc_api.clone_helm_chart_repo(
repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts",
subdir="charts/redhat"
)

def teardown_method(self):
self.hc_api.delete_project()

def test_curl_connection(self):
if self.hc_api.oc_api.shared_cluster:
pytest.skip("Do NOT test on shared cluster")
self.hc_api.package_name = "php-imagestreams"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation()
self.hc_api.package_name = "php-cakephp-application"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation(
values={
"php_version": f"{VERSION}{TAG}",
"namespace": self.hc_api.namespace
}
)
assert self.hc_api.is_s2i_pod_running(pod_name_prefix="cakephp-example")
assert self.hc_api.test_helm_curl_output(
route_name="cakephp-example",
expected_str=check_msg
)

def test_by_helm_test(self):
self.hc_api.package_name = "php-imagestreams"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation()
self.hc_api.package_name = "php-cakephp-application"
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation(
values={
"php_version": f"{VERSION}{TAG}",
"namespace": self.hc_api.namespace
}
)
assert self.hc_api.is_s2i_pod_running(pod_name_prefix="cakephp-example")
assert self.hc_api.test_helm_chart(expected_str=[check_msg])
46 changes: 46 additions & 0 deletions test/test_helm_chart_imagestreams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import sys

import pytest
from pathlib import Path

from container_ci_suite.helm import HelmChartsAPI
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)


test_dir = Path(os.path.abspath(os.path.dirname(__file__)))


class TestHelmRHELPHPImageStreams:

def setup_method(self):
package_name = "php-imagestreams"
path = test_dir
self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, remote=True)
self.hc_api.clone_helm_chart_repo(
repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts",
subdir="charts/redhat"
)

def teardown_method(self):
self.hc_api.delete_project()

@pytest.mark.parametrize(
"version,registry,expected",
[
("8.2-ubi9", "registry.redhat.io/ubi9/php-82:latest", True),
("8.2-ubi8", "registry.redhat.io/ubi8/php-82:latest", True),
("8.1-ubi9", "registry.redhat.io/ubi9/php-81:latest", True),
("8.0-ubi9", "registry.redhat.io/ubi9/php-80:latest", True),
("8.0-ubi8", "registry.redhat.io/ubi8/php-80:latest", True),
("7.4-ubi8", "registry.redhat.io/ubi8/php-74:latest", True),
],
)
def test_package_imagestream(self, version, registry, expected):
assert self.hc_api.helm_package()
assert self.hc_api.helm_installation()
assert self.hc_api.check_imagestreams(version=version, registry=registry) == expected