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 tests for CakePHP App with MySQL database #155

Merged
merged 2 commits into from
Mar 26, 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
88 changes: 71 additions & 17 deletions openshift/templates/cakephp-mysql-persistent.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"openshift.io/long-description": "This template defines resources needed to develop a CakePHP application, including a build configuration, application deployment configuration, and database deployment configuration.",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"openshift.io/documentation-url": "https://github.com/sclorg/cakephp-ex",
"openshift.io/support-url": "https://access.redhat.com",
"template.openshift.io/bindable": "false"
"openshift.io/support-url": "https://access.redhat.com"
}
},
"message": "The following service(s) have been created in your project: ${NAME}, ${DATABASE_SERVICE_NAME}.\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/sclorg/cakephp-ex/blob/master/README.md.",
Expand Down Expand Up @@ -61,7 +60,10 @@
"kind": "Route",
"apiVersion": "route.openshift.io/v1",
"metadata": {
"name": "${NAME}"
"name": "${NAME}",
"annotations": {
"template.openshift.io/expose-uri": "http://{.spec.host}{.spec.path}"
}
},
"spec": {
"host": "${APPLICATION_DOMAIN}",
Expand Down Expand Up @@ -149,23 +151,12 @@
"annotations": {
"description": "Defines how to deploy the application server",
"template.alpha.openshift.io/wait-for-ready": "true",
"image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]"
"image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"},{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.initContainers[0].image\"}]"
}
},
"spec": {
"strategy": {
"type": "Recreate",
"recreateParams": {
"pre": {
"failurePolicy": "Retry",
"execNewPod": {
"command": [
"./migrate-database.sh"
],
"containerName": "cakephp-mysql-persistent"
}
}
}
"type": "Recreate"
},
"replicas": 1,
"selector": {
Expand All @@ -181,9 +172,72 @@
}
},
"spec": {
"initContainers": [
{
"name": "cakephp-init-container",
"image": " ",
"command": [
"./migrate-database.sh"
],
"env": [
{
"name": "DATABASE_SERVICE_NAME",
"value": "${DATABASE_SERVICE_NAME}"
},
{
"name": "DATABASE_USER",
"valueFrom": {
"secretKeyRef" : {
"name" : "${NAME}",
"key" : "database-user"
}
}
},
{
"name": "DATABASE_PASSWORD",
"valueFrom": {
"secretKeyRef" : {
"name" : "${NAME}",
"key" : "database-password"
}
}
},
{
"name": "CAKEPHP_SECRET_TOKEN",
"valueFrom": {
"secretKeyRef" : {
"name" : "${NAME}",
"key" : "cakephp-secret-token"
}
}
},
{
"name": "CAKEPHP_SECURITY_SALT",
"valueFrom": {
"secretKeyRef" : {
"name" : "${NAME}",
"key" : "cakephp-security-salt"
}
}
},
{
"name": "DATABASE_NAME",
"value": "${DATABASE_NAME}"
},
{
"name": "DATABASE_ENGINE",
"value": "${DATABASE_NAME}"
},
{
"name": "APPLICATION_DOMAIN",
"value": "${APPLICATION_DOMAIN}"
}
]
}
],
"containers": [
{
"name": "cakephp-mysql-persistent",
"name": "${NAME}",
"image": " ",
"ports": [
{
Expand Down
28 changes: 26 additions & 2 deletions tests/test_cakephp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,31 @@ def setup_method(self):
def teardown_method(self):
self.oc_api.delete_project()

def test_template_inside_cluster(self):
def test_local_template_inside_cluster(self):
branch_to_test = "master"
expected_output = "Welcome to PHP"
if VERSION.startswith("7.4") or VERSION.startswith("8.0"):
branch_to_test = "4.X"
expected_output = "Welcome to CakePHP 4"
if VERSION.startswith("8.1") or VERSION.startswith("8.2"):
branch_to_test = "5.X"
expected_output = "Welcome to CakePHP 5"

template_json = "../openshift/templates/cakephp.json"
assert self.oc_api.deploy_template(
template=template_json, name_in_template="cakephp-example", expected_output=expected_output,
openshift_args=[
f"SOURCE_REPOSITORY_REF={branch_to_test}",
f"PHP_VERSION={VERSION}",
"NAME=cakephp-example"
]
)
assert self.oc_api.template_deployed(name_in_template="cakephp-example")
assert self.oc_api.check_response_inside_cluster(
name_in_template="cakephp-example", expected_output=expected_output
)

def test_remote_template_inside_cluster(self):
branch_to_test = "master"
expected_output = "Welcome to PHP"
if VERSION.startswith("7.4") or VERSION.startswith("8.0"):
Expand All @@ -45,7 +69,7 @@ def test_template_inside_cluster(self):
name_in_template="cakephp-example", expected_output=expected_output
)

def test_template_by_request(self):
def test_remote_template_by_request(self):
branch_to_test = "master"
expected_output = "Welcome to PHP"
if VERSION.startswith("7.4") or VERSION.startswith("8.0"):
Expand Down
107 changes: 107 additions & 0 deletions tests/test_cakephp_mysql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import os

import pytest
from pathlib import Path

from container_ci_suite.openshift import OpenShiftAPI

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

VERSION = os.getenv("SINGLE_VERSION")
if not VERSION:
VERSION = "8.1-ubi8"


class TestCakePHPAppMySQLExTemplate:

def setup_method(self):
self.oc_api = OpenShiftAPI(pod_name_prefix="cakephp-example")
json_raw_file = self.oc_api.get_raw_url_for_json(container="s2i-php-container", dir="imagestreams",
filename="php-rhel.json")
self.oc_api.import_is(path=json_raw_file, name="php")
json_raw_file = self.oc_api.get_raw_url_for_json(
container="mysql-container", dir="imagestreams", filename="mysql-rhel.json"
)
self.oc_api.import_is(path=json_raw_file, name="mysql")

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

def test_local_template_inside_cluster(self):
branch_to_test = "master"
expected_output = "Welcome to PHP"
if VERSION.startswith("7.4") or VERSION.startswith("8.0"):
branch_to_test = "4.X"
expected_output = "Welcome to CakePHP 4"
if VERSION.startswith("8.1") or VERSION.startswith("8.2"):
branch_to_test = "5.X"
expected_output = "Welcome to CakePHP 5"
template_json = "../openshift/templates/cakephp-mysql-persistent.json"
assert self.oc_api.deploy_template(
template=template_json, name_in_template="cakephp-example", expected_output=expected_output,
openshift_args=[
f"SOURCE_REPOSITORY_REF={branch_to_test}",
f"PHP_VERSION={VERSION}",
"NAME=cakephp-example",
"MYSQL_VERSION=8.0-el8"
]
)
assert self.oc_api.template_deployed(name_in_template="cakephp-example")
assert self.oc_api.check_response_inside_cluster(
name_in_template="cakephp-example", expected_output=expected_output
)

def test_remote_template_inside_cluster(self):
branch_to_test = "master"
expected_output = "Welcome to PHP"
if VERSION.startswith("7.4") or VERSION.startswith("8.0"):
branch_to_test = "4.X"
expected_output = "Welcome to CakePHP 4"
if VERSION.startswith("8.1") or VERSION.startswith("8.2"):
branch_to_test = "5.X"
expected_output = "Welcome to CakePHP 5"

template_json = self.oc_api.get_raw_url_for_json(
container="cakephp-ex", branch=branch_to_test, dir="openshift/templates", filename="cakephp-mysql-persistent.json"
)
assert self.oc_api.deploy_template(
template=template_json, name_in_template="cakephp-example", expected_output=expected_output,
openshift_args=[
f"SOURCE_REPOSITORY_REF={branch_to_test}",
f"PHP_VERSION={VERSION}",
"NAME=cakephp-example",
"MYSQL_VERSION=8.0-el8"
]
)
assert self.oc_api.template_deployed(name_in_template="cakephp-example")
assert self.oc_api.check_response_inside_cluster(
name_in_template="cakephp-example", expected_output=expected_output
)

def test_remote_template_by_request(self):
branch_to_test = "master"
expected_output = "Welcome to PHP"
if VERSION.startswith("7.4") or VERSION.startswith("8.0"):
branch_to_test = "4.X"
expected_output = "Welcome to CakePHP 4"
elif VERSION.startswith("8.1") or VERSION.startswith("8.2"):
branch_to_test = "5.X"
expected_output = "Welcome to CakePHP 5"

template_json = self.oc_api.get_raw_url_for_json(
container="cakephp-ex", branch=branch_to_test, dir="openshift/templates", filename="cakephp-mysql-persistent.json"
)
assert self.oc_api.deploy_template(
template=template_json, name_in_template="cakephp-example", expected_output=expected_output,
openshift_args=[
f"SOURCE_REPOSITORY_REF={branch_to_test}",
f"PHP_VERSION={VERSION}",
"NAME=cakephp-example",
"MYSQL_VERSION=8.0-el8"
]
)
assert self.oc_api.template_deployed(name_in_template="cakephp-example")
assert self.oc_api.check_response_outside_cluster(
protocol="https",
name_in_template="cakephp-example", expected_output=expected_output
)