Skip to content

Commit b37e426

Browse files
committed
Check whether build passes. Do not reuse builds across tests.
Fixes: #444
1 parent e418795 commit b37e426

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

test/run

+47-5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,41 @@ readonly -A gitconfig=(
9191

9292
[[ -n "$DEBUG" ]] && set -x
9393

94+
# Positive test & non-zero exit status = ERROR.
95+
# Negative test & zero exit status = ERROR.
96+
# Tests with '-should-fail-' in their name should fail during a build,
97+
# expecting non-zero exit status.
98+
evaluate_build_result() {
99+
local _result="$1"
100+
local _app="$2"
101+
local _type="positive"
102+
local _test_msg="[PASSED]"
103+
local _ret_code=0
104+
105+
if [[ "$_app" == *"-should-fail-"* ]]; then
106+
_type="negative"
107+
fi
108+
109+
if [[ "$_type" == "positive" && "$_result" != "0" ]]; then
110+
info "TEST FAILED (${_type}), EXPECTED:0 GOT:${_result}"
111+
_ret_code=$_result
112+
elif [[ "$_type" == "negative" && "$_result" == "0" ]]; then
113+
info "TEST FAILED (${_type}), EXPECTED: non-zero GOT:${_result}"
114+
_ret_code=1
115+
fi
116+
if [ $_ret_code != 0 ]; then
117+
cleanup
118+
TESTSUITE_RESULT=1
119+
_test_msg="[FAILED]"
120+
fi
121+
ct_update_test_result "$_test_msg" "$_app" run_s2i_build
122+
123+
if [[ "$_type" == "negative" && "$_result" != "0" ]]; then
124+
_ret_code=127 # even though this is success, the app is still not built
125+
fi
126+
return $_ret_code
127+
}
128+
94129
ct_init
95130
cid_file=$CID_FILE_DIR/$(mktemp -u -p . --suffix=.cid)
96131

@@ -100,27 +135,32 @@ prepare app
100135
check_prep_result $? app || exit
101136
echo "Testing the production image build"
102137
run_s2i_build
103-
ct_check_testcase_result $?
138+
evaluate_build_result $? "default"
104139

105140
TEST_SET=${TESTS:-$TEST_LIST_APP} ct_run_tests_from_testset "app"
106141

107-
echo "Testing the development image build: s2i build -e \"NODE_ENV=development\")"
142+
cleanup
143+
108144
run_s2i_build "-e NODE_ENV=development"
109-
ct_check_testcase_result $?
145+
evaluate_build_result $? "-e NODE_ENV=development"
110146

111147
TEST_SET=${TESTS:-$TEST_LIST_NODE_ENV} ct_run_tests_from_testset "node_env_development"
112148

149+
cleanup
150+
113151
echo "Testing the development image build: s2i build -e \"DEV_MODE=true\")"
114152
run_s2i_build "-e DEV_MODE=true"
115-
ct_check_testcase_result $?
153+
evaluate_build_result $? "-e DEV_MODE=true"
116154

117155
TEST_SET=${TESTS:-$TEST_LIST_DEV_MODE} ct_run_tests_from_testset "dev_mode"
118156

157+
cleanup
158+
119159
echo "Testing proxy safe logging..."
120160
prepare hw
121161
check_prep_result $? hw || exit
122162
run_s2i_build_proxy http://[email protected]:8000 https://[email protected]:8000 > /tmp/build-log 2>&1
123-
ct_check_testcase_result $?
163+
evaluate_build_result $? "proxy"
124164

125165
TEST_SET=${TESTS:-$TEST_LIST_HW} ct_run_tests_from_testset "hw"
126166

@@ -134,4 +174,6 @@ if [[ "$VERSION" != "18" ]]; then
134174
#npm ERR! gyp ERR! node-gyp -v v10.0.1
135175
#npm ERR! gyp ERR! not ok
136176
TEST_SET=${TESTS:-$TEST_LIST_BINARY} ct_run_tests_from_testset "binary"
177+
178+
cleanup
137179
fi

test/test-lib-nodejs.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ run_client_test_suite() {
186186
}
187187

188188
kill_test_application() {
189-
docker kill $(cat $cid_file)
189+
docker stop $(cat $cid_file)
190190
rm $cid_file
191191
}
192192

@@ -688,4 +688,11 @@ function test_latest_imagestreams() {
688688
return $result
689689
}
690690

691+
function cleanup() {
692+
info "Cleaning up the test application image ${IMAGE_NAME}-testapp"
693+
if image_exists ${IMAGE_NAME}-testapp; then
694+
docker rmi -f ${IMAGE_NAME}-testapp
695+
fi
696+
}
697+
691698
# vim: set tabstop=2:shiftwidth=2:expandtab:

0 commit comments

Comments
 (0)