@@ -29,7 +29,11 @@ declare -a CLI_APPS=(
29
29
dotnet-configuration-debug
30
30
dotnet-configuration-release
31
31
)
32
- declare -a WEB_APPS=(asp-net-hello-world asp-net-hello-world-envvar asp-net-hello-world-envvar2)
32
+ declare -a WEB_APPS=(
33
+ asp-net-hello-world
34
+ asp-net-hello-world-envvar
35
+ asp-net-hello-world-envvar2
36
+ )
33
37
34
38
test_dir=" $( readlink -zf $( dirname " ${BASH_SOURCE[0]} " ) ) "
35
39
image_dir=$( readlink -zf ${test_dir} /..)
@@ -47,6 +51,7 @@ image_exists() {
47
51
}
48
52
49
53
container_exists () {
54
+ local cid_file=" $1 "
50
55
image_exists $( cat $cid_file )
51
56
}
52
57
@@ -80,18 +85,23 @@ prepare() {
80
85
}
81
86
82
87
run_test_application () {
83
- docker run --user=100001 ${CONTAINER_ARGS} -d --cidfile=${cid_file} -p ${test_port} :${test_port} ${IMAGE_NAME} -testapp
88
+ local image=" $1 "
89
+ local cid_file=" $2 "
90
+ docker run --user=100001 ${CONTAINER_ARGS} -d --cidfile=${cid_file} -p ${test_port} :${test_port} ${image}
84
91
}
85
92
86
93
run_cli_test_application () {
87
- docker run --user=100001 ${CONTAINER_ARGS} -i --rm ${IMAGE_NAME} -testapp
94
+ local image=$1
95
+ docker run --user=100001 ${CONTAINER_ARGS} -i --rm ${image}
88
96
}
89
97
90
- cleanup_app () {
98
+ cleanup_container () {
99
+ local cid_file=" $1 "
91
100
info " Cleaning up app container ..."
92
101
if [ -f $cid_file ]; then
93
- if container_exists; then
102
+ if container_exists " ${cid_file} " ; then
94
103
docker stop $( cat $cid_file )
104
+ docker rm $( cat $cid_file )
95
105
fi
96
106
fi
97
107
}
@@ -118,7 +128,7 @@ check_command_exists_at()
118
128
local command=$1
119
129
local at=$2
120
130
info " Testing if ${command} is at ${at} "
121
- local actual=$( docker run ${IMAGE_NAME} -testapp bash -c " command -v ${command} " )
131
+ local actual=$( docker run --rm ${IMAGE_NAME} -testapp bash -c " command -v ${command} " )
122
132
if [[ " ${at} _" != " ${actual} _" ]]; then
123
133
info " TEST FAILED (${command} is at ${actual} , expected ${at} )"
124
134
cleanup
@@ -148,7 +158,7 @@ test_s2i_usage() {
148
158
test_docker_run_usage () {
149
159
local expected=" $1 "
150
160
info " Testing 'docker run' usage (${expected} ) ..."
151
- docker run ${IMAGE_NAME} 2>&1 | grep " ${expected} " 2>&1 > /dev/null
161
+ docker run --rm ${IMAGE_NAME} 2>&1 | grep " ${expected} " 2>&1 > /dev/null
152
162
}
153
163
154
164
test_pid_1 () {
@@ -159,7 +169,7 @@ test_pid_1() {
159
169
out=" $( docker exec $( cat ${cid_file} ) /bin/bash -c ' ps --no-headers -o args 1' 2>&1 ) "
160
170
if ! echo " ${out} " | grep " dotnet" | grep -q ' \.dll' ; then
161
171
echo " 'dotnet <assembly>' not process with PID 1. PID 1 process was: '${out} '"
162
- cleanup_app
172
+ cleanup_container " ${cid_file} "
163
173
return 1
164
174
fi
165
175
}
@@ -168,9 +178,10 @@ test_scl_usage() {
168
178
local run_cmd=" $1 "
169
179
local expected=" $2 "
170
180
local cid_file=" $3 "
181
+ local image=" $4 "
171
182
172
- info " Testing the image SCL enable"
173
- out=$( docker run --rm ${IMAGE_NAME } /bin/bash -c " ${run_cmd} " 2>&1 )
183
+ info " Testing the image SCL enable for ' ${run_cmd} ' "
184
+ out=$( docker run --rm ${image } /bin/bash -c " ${run_cmd} " 2>&1 )
174
185
if ! echo " ${out} " | grep -q " ${expected} " ; then
175
186
echo " ERROR[/bin/bash -c " ${run_cmd} " ] Expected '${expected} ', got '${out} '"
176
187
return 1
@@ -233,52 +244,88 @@ test_http() {
233
244
return $result
234
245
}
235
246
236
- test_web_application () {
237
- local cid_file=$( mktemp -u --suffix=.cid)
238
- # Verify that the HTTP connection can be established to test application container
239
- run_test_application &
247
+ test_web_app_http () {
248
+ test_http " /" " Hello world"
249
+ check_result $?
250
+ test_http " /TextFile.txt" " A text file."
251
+ check_result $?
252
+ }
240
253
241
- # Wait for the container to write it's CID file
242
- wait_for_cid
254
+ test_web_app_scl () {
255
+ local image=" $1 "
256
+ local cid_file=" $2 "
243
257
244
- test_scl_usage " dotnet --version" " ${dotnet_version} " " ${cid_file} "
258
+ test_scl_usage " dotnet --version" " ${dotnet_version} " " ${cid_file} " " ${image} "
245
259
check_result $?
246
260
247
261
# Verify $HOME != $CWD. See https://github.com/redhat-developer/s2i-dotnetcore/issues/28
248
- test_scl_usage " pwd" " /opt/app-root/src" " ${cid_file} "
262
+ test_scl_usage " pwd" " /opt/app-root/src" " ${cid_file} " " ${image} "
249
263
check_result $?
250
- test_scl_usage " echo \$ HOME" " /opt/app-root" " ${cid_file} "
264
+ test_scl_usage " echo \$ HOME" " /opt/app-root" " ${cid_file} " " ${image} "
251
265
check_result $?
252
266
253
267
# Verify npm is enabled in the container
254
- test_scl_usage " npm --version" " 2.15.1" " ${cid_file} "
268
+ test_scl_usage " npm --version" " 2.15.1" " ${cid_file} " " ${image} "
269
+ }
255
270
256
- test_http " /" " Hello world"
257
- check_result $?
258
- test_http " /TextFile.txt" " A text file."
259
- check_result $?
271
+ init_web_app () {
272
+ local image=" $1 "
273
+ local cid_file=" $2 "
274
+
275
+ # Verify that the HTTP connection can be established to test application container
276
+ run_test_application " ${image} " " ${cid_file} " &
277
+
278
+ # Wait for the container to write it's CID file
279
+ wait_for_cid
260
280
261
281
test_pid_1 " ${cid_file} "
262
282
check_result $?
283
+ }
284
+
285
+ test_web_application () {
286
+ local app=" $1 "
287
+ info " Starting web application tests for '${app} '"
288
+ prepare ${app}
289
+ run_s2i_build ${app}
290
+ check_result $?
291
+
292
+ image=" ${IMAGE_NAME} -testapp"
263
293
264
- cleanup_app
294
+ # #
295
+ # test the image
296
+ # #
297
+ info " Starting build image tests"
298
+ local cid_file=$( mktemp -u --suffix=.cid)
299
+ init_web_app " ${image} " " ${cid_file} "
300
+ # test application with default user
301
+ test_web_app_scl " ${image} " " ${cid_file} "
302
+ test_web_app_http
303
+
304
+ # test application with random user
305
+ CONTAINER_ARGS=" -u 12345" test_web_app_scl " ${image} " " ${cid_file} "
306
+ CONTAINER_ARGS=" -u 12345" test_web_app_http
307
+ cleanup_container " ${cid_file} "
308
+
309
+ info " All web application tests for '${app} ' finished successfully."
310
+ cleanup ${app}
265
311
}
266
312
267
313
test_openshift_sample_app () {
314
+ local image=" $1 "
268
315
local cid_file=$( mktemp -u --suffix=.cid)
269
316
# Verify that the HTTP connection can be established to test application container
270
- run_test_application &
317
+ run_test_application " ${image} " " ${cid_file} " &
271
318
272
319
# Wait for the container to write it's CID file
273
320
wait_for_cid
274
321
275
- test_scl_usage " dotnet --version" " ${dotnet_version} " " ${cid_file} "
322
+ test_scl_usage " dotnet --version" " ${dotnet_version} " " ${cid_file} " " ${image} "
276
323
check_result $?
277
324
278
325
test_http " /" " Sample pages using ASP.NET Core MVC" " grep \" ASP.NET Core MVC\" | sed -e 's#<li>##g' -e 's#</li>##g' -e 's#^ \\ +##g'"
279
326
check_result $?
280
327
281
- cleanup_app
328
+ cleanup_container " ${cid_file} "
282
329
}
283
330
284
331
echo_details () {
@@ -393,22 +440,21 @@ success_cli() {
393
440
394
441
test_cli_app () {
395
442
local app=" $1 "
396
- info " Testing CLI app: ${app} ..."
443
+ info " Testing CLI app against build image : ${app} ..."
397
444
prepare ${app}
398
445
run_s2i_build ${app}
399
446
check_result $?
400
447
401
448
local expected=" $( get_expected_cli ${app} ) "
402
- local actual_pre=" $( run_cli_test_application ) "
449
+ local actual_pre=" $( run_cli_test_application ${IMAGE_NAME} -testapp ) "
403
450
local actual=" $( filter_cli " ${app} " " ${actual_pre} " ) "
404
451
if ! success_cli " ${app} " " ${actual} " " ${expected} " ; then
405
452
info " Test CLI app: ${app} FAILED."
406
453
echo_details " ${expected} " " ${actual} "
407
454
cleanup ${app}
408
455
exit 1
409
- else
410
- info " Test CLI app: ${app} PASSED."
411
456
fi
457
+ info " Test CLI app (build image): ${app} PASSED."
412
458
cleanup ${app}
413
459
}
414
460
@@ -419,7 +465,7 @@ test_new_web_app() {
419
465
check_result $?
420
466
421
467
local cid_file=$( mktemp -u --suffix=.cid)
422
- run_test_application &
468
+ run_test_application " ${IMAGE_NAME} -testapp " " ${cid_file} " &
423
469
wait_for_cid
424
470
425
471
# installed via DOTNET_NPM_TOOLS
@@ -429,7 +475,7 @@ test_new_web_app() {
429
475
test_http " /js/site.min.js"
430
476
check_result $?
431
477
432
- cleanup_app
478
+ cleanup_container " ${cid_file} "
433
479
info " All tests for the ${app} finished successfully."
434
480
cleanup ${app}
435
481
}
@@ -456,10 +502,10 @@ if [ ${OPENSHIFT_ONLY} = true ]; then
456
502
check_result $?
457
503
458
504
# test application with default user
459
- test_openshift_sample_app
505
+ test_openshift_sample_app " ${IMAGE_NAME} -testapp "
460
506
461
507
# test application with random user
462
- CONTAINER_ARGS=" -u 12345" test_openshift_sample_app
508
+ CONTAINER_ARGS=" -u 12345" test_openshift_sample_app " ${IMAGE_NAME} -testapp "
463
509
464
510
info " All tests for the ${sample_app_url} finished successfully."
465
511
cleanup " ignore-me"
@@ -471,18 +517,7 @@ else
471
517
done
472
518
473
519
for app in ${WEB_APPS[@]} ; do
474
- prepare ${app}
475
- run_s2i_build ${app}
476
- check_result $?
477
-
478
- # test application with default user
479
- test_web_application
480
-
481
- # test application with random user
482
- CONTAINER_ARGS=" -u 12345" test_web_application
483
-
484
- info " All tests for the ${app} finished successfully."
485
- cleanup ${app}
520
+ test_web_application " ${app} "
486
521
done
487
522
488
523
test_new_web_app
0 commit comments