Skip to content

Commit 3bf194c

Browse files
authored
Merge pull request #282 from sclorg/add_tests_with_postgresql
Add tests for NodeJS App with Postgresql database
2 parents 0929638 + bffaeb3 commit 3bf194c

2 files changed

Lines changed: 91 additions & 4 deletions

File tree

openshift/templates/nodejs-postgresql-persistent.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"iconClass": "icon-nodejs",
1111
"openshift.io/long-description": "This template defines resources needed to develop a NodeJS application, including a build configuration, application deployment configuration, and database deployment configuration.",
1212
"openshift.io/provider-display-name": "Red Hat, Inc.",
13-
"openshift.io/documentation-url": "https://github.com/nodeshift-starters/nodejs-rest-http-crud",
13+
"openshift.io/documentation-url": "https://github.com/sclorg/nodejs-ex",
1414
"openshift.io/support-url": "https://access.redhat.com",
1515
"template.openshift.io/bindable": "false"
1616
}
@@ -60,7 +60,10 @@
6060
"kind": "Route",
6161
"apiVersion": "route.openshift.io/v1",
6262
"metadata": {
63-
"name": "${NAME}"
63+
"name": "${NAME}",
64+
"annotations": {
65+
"template.openshift.io/expose-uri": "http://{.spec.host}{.spec.path}"
66+
}
6467
},
6568
"spec": {
6669
"host": "${APPLICATION_DOMAIN}",
@@ -179,7 +182,7 @@
179182
"spec": {
180183
"containers": [
181184
{
182-
"name": "nodejs-postgresql-persistent",
185+
"name": "${NAME}",
183186
"image": " ",
184187
"ports": [
185188
{
@@ -448,7 +451,7 @@
448451
"displayName": "Git Repository URL",
449452
"description": "The URL of the repository with your application source code.",
450453
"required": true,
451-
"value": "https://github.com/nodeshift-starters/nodejs-rest-http-crud.git"
454+
"value": "https://github.com/sclorg/nodejs-ex.git"
452455
},
453456
{
454457
"name": "SOURCE_REPOSITORY_REF",

tests/test_nodejs_postgresql.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import os
2+
3+
import pytest
4+
from pathlib import Path
5+
6+
from container_ci_suite.openshift import OpenShiftAPI
7+
8+
test_dir = Path(os.path.abspath(os.path.dirname(__file__)))
9+
10+
VERSION=os.getenv("SINGLE_VERSION")
11+
if not VERSION:
12+
VERSION="20-ubi8"
13+
14+
class TestNodeJSAppPostgreSQLExTemplate:
15+
16+
def setup_method(self):
17+
self.oc_api = OpenShiftAPI(pod_name_prefix="nodejs-example")
18+
json_raw_file = self.oc_api.get_raw_url_for_json(
19+
container="s2i-nodejs-container", dir="imagestreams", filename="nodejs-rhel.json"
20+
)
21+
self.oc_api.import_is(path=json_raw_file, name="node")
22+
json_raw_file = self.oc_api.get_raw_url_for_json(
23+
container="postgresql-container", dir="imagestreams", filename="postgresql-rhel.json"
24+
)
25+
self.oc_api.import_is(path=json_raw_file, name="postgresql")
26+
27+
def teardown_method(self):
28+
self.oc_api.delete_project()
29+
30+
def test_local_template_inside_cluster(self):
31+
expected_output = "Node.js Crud Application"
32+
template_json = "../openshift/templates/nodejs-postgresql-persistent.json"
33+
assert self.oc_api.deploy_template(
34+
template=template_json, name_in_template="nodejs-example", expected_output=expected_output,
35+
openshift_args=[
36+
"SOURCE_REPOSITORY_REF=master",
37+
f"NODEJS_VERSION={VERSION}",
38+
"NAME=nodejs-example",
39+
"POSTGRESQL_VERSION=12-el8"
40+
]
41+
)
42+
assert self.oc_api.template_deployed(name_in_template="nodejs-example")
43+
assert self.oc_api.check_response_inside_cluster(
44+
name_in_template="nodejs-example", expected_output=expected_output
45+
)
46+
47+
48+
def test_remote_template_inside_cluster(self):
49+
expected_output = "Node.js Crud Application"
50+
template_json = self.oc_api.get_raw_url_for_json(
51+
container="nodejs-ex", dir="openshift/templates", filename="nodejs-postgresql-persistent.json"
52+
)
53+
assert self.oc_api.deploy_template(
54+
template=template_json, name_in_template="dancer-example", expected_output=expected_output,
55+
openshift_args=[
56+
"SOURCE_REPOSITORY_REF=master",
57+
f"NODEJS_VERSION={VERSION}",
58+
"NAME=nodejs-example",
59+
"POSTGRESQL_VERSION=12-el8"
60+
]
61+
)
62+
assert self.oc_api.template_deployed(name_in_template="nodejs-example")
63+
assert self.oc_api.check_response_inside_cluster(
64+
name_in_template="nodejs-example", expected_output=expected_output
65+
)
66+
67+
def test_remote_template_by_request(self):
68+
expected_output = "Node.js Crud Application"
69+
template_json = self.oc_api.get_raw_url_for_json(
70+
container="nodejs-ex", dir="openshift/templates", filename="nodejs-postgresql-persistent.json"
71+
)
72+
assert self.oc_api.deploy_template(
73+
template=template_json, name_in_template="nodejs-example", expected_output=expected_output,
74+
openshift_args=[
75+
"SOURCE_REPOSITORY_REF=master",
76+
f"NODEJS_VERSION={VERSION}",
77+
"NAME=nodejs-example",
78+
"POSTGRESQL_VERSION=12-el8"
79+
]
80+
)
81+
assert self.oc_api.template_deployed(name_in_template="nodejs-example")
82+
assert self.oc_api.check_response_outside_cluster(
83+
name_in_template="nodejs-example", expected_output=expected_output
84+
)

0 commit comments

Comments
 (0)