9
9
test -n " ${IMAGE_NAME-} " || false ' make sure $IMAGE_NAME is defined'
10
10
test -n " ${VERSION-} " || false ' make sure $VERSION is defined'
11
11
12
+ TEST_LIST=" \
13
+ test_s2i_usage
14
+ test_docker_run_usage
15
+ test_scl_usage
16
+ test_application
17
+ test_application_user
18
+ test_ssl
19
+ test_ssl_own_cert
20
+ ct_npm_works
21
+ "
22
+
23
+ ct_enable_cleanup
24
+
12
25
# TODO: Make command compatible for Mac users
13
26
test_dir=" $( readlink -zf $( dirname " ${BASH_SOURCE[0]} " ) ) "
14
27
image_dir=$( readlink -zf ${test_dir} /..)
15
-
28
+ test_short_summary=' '
29
+ TESTSUITE_RESULT=1
16
30
source " ${test_dir} /test-lib.sh"
17
31
18
32
# TODO: This should be part of the image metadata
@@ -76,6 +90,14 @@ cleanup() {
76
90
docker rmi -f ${IMAGE_NAME} -testapp
77
91
fi
78
92
rm -rf ${test_dir} /test-app/.git
93
+
94
+ echo " $test_short_summary "
95
+
96
+ if [ $TESTSUITE_RESULT -eq 0 ] ; then
97
+ echo " Tests for ${IMAGE_NAME} succeeded."
98
+ else
99
+ echo " Tests for ${IMAGE_NAME} failed."
100
+ fi
79
101
}
80
102
81
103
check_result () {
@@ -176,32 +198,41 @@ test_application() {
176
198
wait_for_cid
177
199
178
200
test_scl_usage " php --version" " $VERSION "
179
- check_result $?
201
+ [[ " $? " != " 0 " ]] && return 1
180
202
181
203
test_session ${test_port}
182
- check_result $?
204
+ [[ " $? " != " 0 " ]] && return 1
183
205
184
206
test_connection ${test_port}
185
- check_result $?
207
+ [[ " $? " != " 0" ]] && return 1
208
+
186
209
test_connection ${test_port_ssl} https
187
- check_result $?
210
+ [[ " $? " != " 0" ]] && return 1
211
+
188
212
cleanup_test_app
189
213
}
190
214
215
+ test_application_user () {
216
+ # Test application with random uid
217
+ CONTAINER_ARGS=" --user 12345" test_application
218
+ }
219
+
191
220
test_ssl () {
192
221
local cert_dir=/tmp
193
222
local cert_base=mycert
194
223
ct_gen_self_signed_cert_pem ${cert_dir} ${cert_base}
195
224
local private_key=${cert_dir} /${cert_base} -cert-selfsigned.pem
196
225
local cert_file=${cert_dir} /${cert_base} -key.pem
197
-
198
226
}
199
227
200
228
test_ssl_own_cert () {
229
+ local result=0
230
+ cleanup_test_app
201
231
ct_s2i_build_as_df file://${test_dir} /self-signed-ssl ${IMAGE_NAME} ${IMAGE_NAME} -test-self-signed-ssl ${s2i_args} $( ct_build_s2i_npm_variables)
202
232
docker run -d --user=100001 ${run_args} --cidfile=${cid_file} ${IMAGE_NAME} -test-self-signed-ssl
203
233
test_connection ${test_port_ssl} https
204
- check_result $?
234
+ [[ " $? " != " 0" ]] && return 1
235
+
205
236
echo | openssl s_client -showcerts -servername $( container_ip) -connect $( container_ip) :${test_port_ssl} 2> /dev/null | openssl x509 -inform pem -noout -text > ./servercert
206
237
openssl x509 -in ${test_dir} /self-signed-ssl/httpd-ssl/certs/server-cert-selfsigned.pem -inform pem -noout -text > ./configcert
207
238
diff ./configcert ./servercert > cert.diff
@@ -217,28 +248,27 @@ prepare
217
248
run_s2i_build
218
249
check_result $?
219
250
220
- # Verify the 'usage' script is working properly when running the base image with 's2i usage ...'
221
- test_s2i_usage
222
- check_result $?
223
-
224
- # Verify the 'usage' script is working properly when running the base image with 'docker run ...'
225
- test_docker_run_usage
226
- check_result $?
227
-
228
- # Test application with default uid
229
- test_application
230
-
231
- # Test application with random uid
232
- CONTAINER_ARGS=" --user 12345" test_application
233
-
234
- echo " Testing npm availibility"
235
- ct_npm_works
236
- check_result $?
251
+ function run_all_tests() {
252
+ local suite_result=0
253
+ for test_case in $TEST_LIST ; do
254
+ : " Running test $test_case ...."
255
+ if $test_case ; then
256
+ printf -v test_short_summary " ${test_short_summary} [PASSED] $test_case \n"
257
+ else
258
+ printf -v test_short_summary " ${test_short_summary} [FAILED] $test_case \n"
259
+ suite_result=1
260
+ [ -n " ${FAIL_QUICKLY:- } " ] && echo " $sum " && return $suite_result
261
+ fi
262
+ done ;
263
+ return $suite_result
264
+ }
237
265
238
- cleanup
266
+ # Run the chosen tests
267
+ TEST_LIST=${TESTS:- $TEST_LIST } run_all_tests
268
+ if [[ " $? " == " 0" ]]; then
269
+ TESTSUITE_RESULT=0
270
+ fi
239
271
240
- test_ssl_own_cert
241
- check_result $?
242
272
cleanup
243
273
244
274
info " All tests finished successfully."
0 commit comments