Skip to content

Commit 595683b

Browse files
committed
Add integration test for Reverse Proxy
1 parent 6e965d4 commit 595683b

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
8+
9+
IMAGE="${1}"
10+
TAG="${2}"
11+
ARCH="${3}"
12+
13+
14+
###
15+
### Load Library
16+
###
17+
# shellcheck disable=SC1090,SC1091
18+
. "${CWD}/.lib.sh"
19+
20+
21+
###
22+
### Universal ports
23+
###
24+
# shellcheck disable=SC2034
25+
HOST_PORT_HTTP="8093"
26+
# shellcheck disable=SC2034
27+
HOST_PORT_HTTPS="8493"
28+
29+
###
30+
### Universal container names
31+
###
32+
# shellcheck disable=SC2034
33+
NAME_HTTPD="$( get_random_name )"
34+
# shellcheck disable=SC2034
35+
NAME_PHPFPM="$( get_random_name )"
36+
# shellcheck disable=SC2034
37+
NAME_RPROXY="$( get_random_name )"
38+
39+
40+
41+
#---------------------------------------------------------------------------------------------------
42+
# DEFINES
43+
#---------------------------------------------------------------------------------------------------
44+
45+
###
46+
### GLOBALS
47+
###
48+
#DOCROOT="htdocs"
49+
MOUNT_CONT="/var/www/default"
50+
MOUNT_HOST="$( tmp_dir )"
51+
52+
53+
54+
#---------------------------------------------------------------------------------------------------
55+
# APPS
56+
#---------------------------------------------------------------------------------------------------
57+
58+
###
59+
### Application 1
60+
###
61+
APP1_URL="http://localhost:${HOST_PORT_HTTP}"
62+
#APP1_EXT="nodejs"
63+
APP1_HDR=""
64+
APP1_TXT="hello via httpd with NodeJS"
65+
#create_app "${MOUNT_HOST}" "${DOCROOT}" "" "index.${APP1_EXT}" "<?php echo '${APP1_TXT}';"
66+
cat << EOF > "${MOUNT_HOST}/app.js"
67+
const http = require('http');
68+
const server = http.createServer((req, res) => {
69+
res.statusCode = 200;
70+
res.setHeader('Content-Type', 'text/plain');
71+
res.write('[OK]\n');
72+
res.write('${APP1_TXT}\n');
73+
res.end();
74+
});
75+
server.listen(3000, '0.0.0.0');
76+
EOF
77+
78+
79+
80+
#---------------------------------------------------------------------------------------------------
81+
# START
82+
#---------------------------------------------------------------------------------------------------
83+
84+
###
85+
### Start NodeJS Container
86+
###
87+
run "docker run -d --platform ${ARCH} --name ${NAME_RPROXY} \
88+
-v ${MOUNT_HOST}:${MOUNT_CONT} \
89+
node:19-alpine node /var/www/default/app.js >/dev/null"
90+
91+
92+
###
93+
### Start HTTPD Container
94+
###
95+
run "docker run -d --platform ${ARCH} --name ${NAME_HTTPD} \
96+
-v ${MOUNT_HOST}:${MOUNT_CONT} \
97+
-p 127.0.0.1:${HOST_PORT_HTTP}:80 \
98+
-p 127.0.0.1:${HOST_PORT_HTTPS}:443 \
99+
-e DEBUG_ENTRYPOINT=4 \
100+
-e DEBUG_RUNTIME=2 \
101+
-e MAIN_VHOST_BACKEND=conf:rproxy:http:${NAME_RPROXY}:3000 \
102+
--link ${NAME_RPROXY} \
103+
${IMAGE}:${TAG} >/dev/null"
104+
105+
106+
107+
#---------------------------------------------------------------------------------------------------
108+
# TESTS
109+
#---------------------------------------------------------------------------------------------------
110+
111+
###
112+
### Test: APP1
113+
###
114+
if ! test_vhost_response "${APP1_TXT}" "${APP1_URL}" "${APP1_HDR}"; then
115+
docker_logs "${NAME_PHPFPM}"
116+
docker_logs "${NAME_HTTPD}"
117+
docker_stop "${NAME_PHPFPM}"
118+
docker_stop "${NAME_HTTPD}"
119+
log "fail" "'${APP1_TXT}' not found in ${APP1_URL}"
120+
exit 1
121+
fi
122+
123+
124+
125+
#---------------------------------------------------------------------------------------------------
126+
# GENERIC
127+
#---------------------------------------------------------------------------------------------------
128+
129+
###
130+
### Test: Errors
131+
###
132+
if ! test_docker_logs_err "${NAME_HTTPD}"; then
133+
docker_logs "${NAME_PHPFPM}"
134+
docker_logs "${NAME_HTTPD}"
135+
docker_stop "${NAME_PHPFPM}"
136+
docker_stop "${NAME_HTTPD}"
137+
log "fail" "Found errors in docker logs"
138+
exit 1
139+
fi
140+
141+
142+
###
143+
### Cleanup
144+
###
145+
docker_stop "${NAME_PHPFPM}"
146+
docker_stop "${NAME_HTTPD}"
147+
log "ok" "Test succeeded"

0 commit comments

Comments
 (0)