Skip to content

Commit

Permalink
Merge pull request #155 from sclorg/add_tests_mysql
Browse files Browse the repository at this point in the history
Add tests for CakePHP App with MySQL database
  • Loading branch information
phracek authored Mar 26, 2024
2 parents 948573c + 64d61cc commit b9b1c61
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 19 deletions.
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
)

0 comments on commit b9b1c61

Please sign in to comment.