Skip to content

Commit

Permalink
tests: make sure a failed test fails whole testsuite
Browse files Browse the repository at this point in the history
and use ct_ function for checking result
  • Loading branch information
zmiklank committed Mar 13, 2023
1 parent ed62e9a commit 3af3356
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions test/run
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ run_s2i_build() {
prepare() {
if ! image_exists ${IMAGE_NAME}; then
echo "ERROR: The image ${IMAGE_NAME} must exist before this script is executed."
exit 1
return 1
fi
# TODO: S2I build require the application is a valid 'GIT' repository, we
# should remove this restriction in the future when a file:// is used.
Expand All @@ -69,14 +69,6 @@ run_test_application() {
docker run -d --user=100001 ${run_args} --cidfile=${cid_file} ${IMAGE_NAME}-testapp
}

check_result() {
local result="$1"
if [[ "$result" != "0" ]]; then
TESTCASE_RESULT=1
fi
return $result
}

wait_for_cid() {
local max_attempts=10
local sleep_time=1
Expand Down Expand Up @@ -165,19 +157,19 @@ test_application() {

# Wait for the container to write it's CID file
wait_for_cid
check_result $?
ct_check_testcase_result $?

test_scl_usage "php --version" "$VERSION"
check_result $?
ct_check_testcase_result $?

test_session ${test_port}
check_result $?
ct_check_testcase_result $?

test_connection ${test_port}
check_result $?
ct_check_testcase_result $?

test_connection ${test_port_ssl} https
check_result $?
ct_check_testcase_result $?
}

test_application_user() {
Expand All @@ -199,12 +191,12 @@ test_ssl_own_cert() {
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)
docker run -d --user=100001 ${run_args} --cidfile=${cid_file} ${IMAGE_NAME}-test-self-signed-ssl
test_connection ${test_port_ssl} https
check_result $?
ct_check_testcase_result $?

echo | openssl s_client -showcerts -servername $(container_ip) -connect $(container_ip):${test_port_ssl} 2>/dev/null | openssl x509 -inform pem -noout -text >./servercert
openssl x509 -in ${test_dir}/self-signed-ssl/httpd-ssl/certs/server-cert-selfsigned.pem -inform pem -noout -text >./configcert
diff ./configcert ./servercert >cert.diff
check_result $?
ct_check_testcase_result $?
}

test_build_from_dockerfile() {
Expand All @@ -213,15 +205,14 @@ test_build_from_dockerfile() {
'https://github.com/sclorg/cakephp-ex.git' \
'Welcome to your CakePHP application on OpenShift' \
app-src
check_result $?
ct_check_testcase_result $?
ct_test_app_dockerfile ${test_dir}/examples/from-dockerfile/Dockerfile.s2i \
'https://github.com/sclorg/cakephp-ex.git' \
'Welcome to your CakePHP application on OpenShift' \
app-src
check_result $?
ct_check_testcase_result $?
}

set -x
ct_init

# Since we built the candidate image locally, we don't want S2I attempt to pull
Expand All @@ -230,6 +221,6 @@ s2i_args="--pull-policy=never"

prepare
run_s2i_build
check_result $?
ct_check_testcase_result $?

TEST_SET=${TESTS:-$TEST_LIST} ct_run_tests_from_testset "php_tests"

0 comments on commit 3af3356

Please sign in to comment.