Skip to content

Commit 80ac275

Browse files
phracekhhorak
authored andcommitted
Run all tests
Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 30aadf0 commit 80ac275

File tree

2 files changed

+121
-53
lines changed

2 files changed

+121
-53
lines changed

7.2/test/run

+64-26
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,24 @@
99
test -n "${IMAGE_NAME-}" || false 'make sure $IMAGE_NAME is defined'
1010
test -n "${VERSION-}" || false 'make sure $VERSION is defined'
1111

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+
1225
# TODO: Make command compatible for Mac users
1326
test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))"
1427
image_dir=$(readlink -zf ${test_dir}/..)
28+
test_short_summary=''
29+
TESTSUITE_RESULT=1
1530

1631
source "${test_dir}/test-lib.sh"
1732

@@ -76,6 +91,13 @@ cleanup() {
7691
docker rmi -f ${IMAGE_NAME}-testapp
7792
fi
7893
rm -rf ${test_dir}/test-app/.git
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
79101
}
80102

81103
check_result() {
@@ -176,18 +198,32 @@ test_application() {
176198
wait_for_cid
177199

178200
test_scl_usage "php --version" "$VERSION"
179-
check_result $?
201+
if [[ "$?" != "0" ]]; then
202+
return 1
203+
fi
180204

181205
test_session ${test_port}
182-
check_result $?
206+
if [[ "$?" != "0" ]]; then
207+
return 1
208+
fi
183209

184210
test_connection ${test_port}
185-
check_result $?
211+
if [[ "$?" != "0" ]]; then
212+
return 1
213+
fi
214+
186215
test_connection ${test_port_ssl} https
187-
check_result $?
216+
if [[ "$?" != "0" ]]; then
217+
return 1
218+
fi
188219
cleanup_test_app
189220
}
190221

222+
test_application_user() {
223+
# Test application with random uid
224+
CONTAINER_ARGS="--user 12345" test_application
225+
}
226+
191227
test_ssl() {
192228
local cert_dir=/tmp
193229
local cert_base=mycert
@@ -198,10 +234,14 @@ test_ssl() {
198234
}
199235

200236
test_ssl_own_cert() {
237+
cleanup_test_app
201238
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)
202239
docker run -d --user=100001 ${run_args} --cidfile=${cid_file} ${IMAGE_NAME}-test-self-signed-ssl
203240
test_connection ${test_port_ssl} https
204-
check_result $?
241+
if [[ "$?" != "0" ]]; then
242+
return 1
243+
fi
244+
205245
echo | openssl s_client -showcerts -servername $(container_ip) -connect $(container_ip):${test_port_ssl} 2>/dev/null | openssl x509 -inform pem -noout -text >./servercert
206246
openssl x509 -in ${test_dir}/self-signed-ssl/httpd-ssl/certs/server-cert-selfsigned.pem -inform pem -noout -text >./configcert
207247
diff ./configcert ./servercert >cert.diff
@@ -217,28 +257,26 @@ prepare
217257
run_s2i_build
218258
check_result $?
219259

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 $?
237-
238-
cleanup
260+
function run_all_tests() {
261+
local suite_result=0
262+
for test_case in $TEST_LIST; do
263+
: "Running test $test_case ...."
264+
if $test_case; then
265+
printf -v test_short_summary "${test_short_summary}[PASSED] $test_case\n"
266+
else
267+
printf -v test_short_summary "${test_short_summary}[FAILED] $test_case\n"
268+
suite_result=1
269+
[ -n "${FAIL_QUICKLY:-}" ] && echo "$sum" && return $suite_result
270+
fi
271+
done;
272+
return $suite_result
273+
}
239274

240-
test_ssl_own_cert
241-
check_result $?
275+
# Run the chosen tests
276+
TEST_LIST=${TESTS:-$TEST_LIST} run_all_tests
277+
if [[ "$?" == "0" ]]; then
278+
TESTSUITE_RESULT=0
279+
fi
242280
cleanup
243281

244282
info "All tests finished successfully."

7.3/test/run

+57-27
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,24 @@
99
test -n "${IMAGE_NAME-}" || false 'make sure $IMAGE_NAME is defined'
1010
test -n "${VERSION-}" || false 'make sure $VERSION is defined'
1111

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+
1225
# TODO: Make command compatible for Mac users
1326
test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))"
1427
image_dir=$(readlink -zf ${test_dir}/..)
15-
28+
test_short_summary=''
29+
TESTSUITE_RESULT=1
1630
source "${test_dir}/test-lib.sh"
1731

1832
# TODO: This should be part of the image metadata
@@ -76,6 +90,14 @@ cleanup() {
7690
docker rmi -f ${IMAGE_NAME}-testapp
7791
fi
7892
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
79101
}
80102

81103
check_result() {
@@ -176,32 +198,41 @@ test_application() {
176198
wait_for_cid
177199

178200
test_scl_usage "php --version" "$VERSION"
179-
check_result $?
201+
[[ "$?" != "0" ]] && return 1
180202

181203
test_session ${test_port}
182-
check_result $?
204+
[[ "$?" != "0" ]] && return 1
183205

184206
test_connection ${test_port}
185-
check_result $?
207+
[[ "$?" != "0" ]] && return 1
208+
186209
test_connection ${test_port_ssl} https
187-
check_result $?
210+
[[ "$?" != "0" ]] && return 1
211+
188212
cleanup_test_app
189213
}
190214

215+
test_application_user() {
216+
# Test application with random uid
217+
CONTAINER_ARGS="--user 12345" test_application
218+
}
219+
191220
test_ssl() {
192221
local cert_dir=/tmp
193222
local cert_base=mycert
194223
ct_gen_self_signed_cert_pem ${cert_dir} ${cert_base}
195224
local private_key=${cert_dir}/${cert_base}-cert-selfsigned.pem
196225
local cert_file=${cert_dir}/${cert_base}-key.pem
197-
198226
}
199227

200228
test_ssl_own_cert() {
229+
local result=0
230+
cleanup_test_app
201231
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)
202232
docker run -d --user=100001 ${run_args} --cidfile=${cid_file} ${IMAGE_NAME}-test-self-signed-ssl
203233
test_connection ${test_port_ssl} https
204-
check_result $?
234+
[[ "$?" != "0" ]] && return 1
235+
205236
echo | openssl s_client -showcerts -servername $(container_ip) -connect $(container_ip):${test_port_ssl} 2>/dev/null | openssl x509 -inform pem -noout -text >./servercert
206237
openssl x509 -in ${test_dir}/self-signed-ssl/httpd-ssl/certs/server-cert-selfsigned.pem -inform pem -noout -text >./configcert
207238
diff ./configcert ./servercert >cert.diff
@@ -217,28 +248,27 @@ prepare
217248
run_s2i_build
218249
check_result $?
219250

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+
}
237265

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
239271

240-
test_ssl_own_cert
241-
check_result $?
242272
cleanup
243273

244274
info "All tests finished successfully."

0 commit comments

Comments
 (0)