Skip to content

Commit

Permalink
Check whether build passes. Do not reuse builds across tests.
Browse files Browse the repository at this point in the history
Fixes: #444
  • Loading branch information
SlouchyButton authored and phracek committed Sep 30, 2024
1 parent e418795 commit 4e2ef5a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
52 changes: 47 additions & 5 deletions test/run
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,41 @@ readonly -A gitconfig=(

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

# Positive test & non-zero exit status = ERROR.
# Negative test & zero exit status = ERROR.
# Tests with '-should-fail-' in their name should fail during a build,
# expecting non-zero exit status.
evaluate_build_result() {
local _result="$1"
local _app="$2"
local _type="positive"
local _test_msg="[PASSED]"
local _ret_code=0

if [[ "$_app" == *"-should-fail-"* ]]; then
_type="negative"
fi

if [[ "$_type" == "positive" && "$_result" != "0" ]]; then
info "TEST FAILED (${_type}), EXPECTED:0 GOT:${_result}"
_ret_code=$_result
elif [[ "$_type" == "negative" && "$_result" == "0" ]]; then
info "TEST FAILED (${_type}), EXPECTED: non-zero GOT:${_result}"
_ret_code=1
fi
if [ $_ret_code != 0 ]; then
cleanup
TESTSUITE_RESULT=1
_test_msg="[FAILED]"
fi
ct_update_test_result "$_test_msg" "$_app" run_s2i_build

if [[ "$_type" == "negative" && "$_result" != "0" ]]; then
_ret_code=127 # even though this is success, the app is still not built
fi
return $_ret_code
}

ct_init
cid_file=$CID_FILE_DIR/$(mktemp -u -p . --suffix=.cid)

Expand All @@ -100,27 +135,32 @@ prepare app
check_prep_result $? app || exit
echo "Testing the production image build"
run_s2i_build
ct_check_testcase_result $?
evaluate_build_result $? "default"

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

echo "Testing the development image build: s2i build -e \"NODE_ENV=development\")"
cleanup

run_s2i_build "-e NODE_ENV=development"
ct_check_testcase_result $?
evaluate_build_result $? "-e NODE_ENV=development"

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

cleanup

echo "Testing the development image build: s2i build -e \"DEV_MODE=true\")"
run_s2i_build "-e DEV_MODE=true"
ct_check_testcase_result $?
evaluate_build_result $? "-e DEV_MODE=true"

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

cleanup

echo "Testing proxy safe logging..."
prepare hw
check_prep_result $? hw || exit
run_s2i_build_proxy http://[email protected]:8000 https://[email protected]:8000 > /tmp/build-log 2>&1
ct_check_testcase_result $?
evaluate_build_result $? "proxy"

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

Expand All @@ -134,4 +174,6 @@ if [[ "$VERSION" != "18" ]]; then
#npm ERR! gyp ERR! node-gyp -v v10.0.1
#npm ERR! gyp ERR! not ok
TEST_SET=${TESTS:-$TEST_LIST_BINARY} ct_run_tests_from_testset "binary"

cleanup
fi
9 changes: 8 additions & 1 deletion test/test-lib-nodejs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ run_client_test_suite() {
}

kill_test_application() {
docker kill $(cat $cid_file)
docker stop $(cat $cid_file)
rm $cid_file
}

Expand Down Expand Up @@ -688,4 +688,11 @@ function test_latest_imagestreams() {
return $result
}

function cleanup() {
info "Cleaning up the test application image ${IMAGE_NAME}-testapp"
if image_exists ${IMAGE_NAME}-testapp; then
docker rmi -f ${IMAGE_NAME}-testapp
fi
}

# vim: set tabstop=2:shiftwidth=2:expandtab:

0 comments on commit 4e2ef5a

Please sign in to comment.