-
Notifications
You must be signed in to change notification settings - Fork 287
/
run
executable file
·179 lines (148 loc) · 4.83 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
#
# The 'run' performs a simple test that verifies that STI image.
# The main focus here is to exercise the STI scripts.
#
# IMAGE_NAME specifies a name of the candidate image used for testing.
# The image has to be available before this script is executed.
THISDIR=$(dirname ${BASH_SOURCE[0]})
TEST_LIST_APP="\
test_run_app_application
test_s2i_usage
test_scl_usage
test_connection
test_docker_run_usage
test_npm_functionality
test_check_build_using_dockerfile
test_nodemon_removed
test_npm_cache_cleared
test_npm_tmp_cleared
kill_test_application
test_dev_mode_true_development
test_dev_mode_false_production
test_node_cmd_development_init_wrapper_true
test_node_cmd_production_init_wrapper_true
test_node_cmd_development_init_wrapper_false
test_init_wrapper_true_development
test_init_wrapper_false_development
"
TEST_LIST_BINARY="\
test_run_binary_application
test_node_cmd_development_init_wrapper_true
"
TEST_LIST_NODE_ENV="\
test_run_app_application
test_connection
test_nodemon_present
test_npm_cache_exists
kill_test_application
test_dev_mode_true_development
test_dev_mode_false_development
test_node_cmd_development_init_wrapper_true
test_node_cmd_production_init_wrapper_true
test_node_cmd_production_init_wrapper_false
"
TEST_LIST_DEV_MODE="\
test_run_app_application
test_connection
test_nodemon_present
test_npm_cache_exists
kill_test_application
test_dev_mode_true_development
test_dev_mode_false_production
"
TEST_LIST_HW="\
test_safe_logging
test_run_hw_application
test_incremental_build
test_build_express_webapp
test_node_cmd_development_init_wrapper_true
test_init_wrapper_false_development
"
source "${THISDIR}/test-lib.sh"
source "${THISDIR}/test-lib-nodejs.sh"
test -n $IMAGE_NAME \
-a -n $VERSION
test_dir="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
image_dir="$(readlink -f ${test_dir}/..)"
# Since we built the candidate image locally, we don't want S2I attempt to pull
# it from Docker hub
s2i_args="--pull-policy=never "
# TODO: This should be part of the image metadata
test_port=8080
# Common git configuration
readonly -A gitconfig=(
[user.name]="builder"
[user.email]="build@localhost"
[commit.gpgsign]="false"
)
[[ -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)
# Build the application image twice to ensure the 'save-artifacts' and
# 'restore-artifacts' scripts are working properly
prepare app
check_prep_result $? app || exit
echo "Testing the production image build"
run_s2i_build
evaluate_build_result $? "default"
TEST_SET=${TESTS:-$TEST_LIST_APP} ct_run_tests_from_testset "app"
cleanup
run_s2i_build "-e NODE_ENV=development"
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"
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://user.password@0.0.0.0:8000 https://user.password@0.0.0.0:8000 > /tmp/build-log 2>&1
evaluate_build_result $? "proxy"
TEST_SET=${TESTS:-$TEST_LIST_HW} ct_run_tests_from_testset "hw"
if [[ "$VERSION" != "18" ]]; then
# This test is not available for NodeJS-18
# There is a traceback in NodeJS. It reached EOL support.
#npm ERR! gyp ERR! System Linux 6.9.12-200.fc40.x86_64
#npm ERR! gyp ERR! command "/usr/bin/node-18" "/usr/lib/node_modules_18/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
#npm ERR! gyp ERR! cwd /opt/app-root/src/node_modules/node-rdkafka
#npm ERR! gyp ERR! node -v v18.19.0
#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