Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Make tests work also for rootless containers #192

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions test/run
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ TEST_LIST_PERL_APP="test_perl_directive"

. $test_dir/test-lib.sh

# TODO: This should be part of the image metadata
test_port=8080

info() {
echo -e "\n\e[1m[INFO] $@...\e[0m\n"
Expand All @@ -45,7 +43,14 @@ container_exists() {
}

container_ip() {
docker inspect --format="{{ .NetworkSettings.IPAddress }}" $(cat $cid_file)
# local ip=$(docker inspect --format="{{ .NetworkSettings.IPAddress }}" $(cat $cid_file))
# echo ${ip:-localhost}
echo localhost
}

test_port() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function could be a part of container-common-scripts.
The first parameter would be port and the second parameter would be a protocol

The results would be echo as you already have it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I will need to make time to get back to this soon and get this PR to a mergeable state.

local port=$(docker inspect --format '{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort }}' $(cat $cid_file))
echo ${port:-8080}
}

run_s2i_build() {
Expand All @@ -69,8 +74,8 @@ prepare() {

run_test_application() {
run_args=${CONTAINER_ARGS:-}
info "Running docker run --user=10001 ${run_args} -d --cidfile=${cid_file} ${IMAGE_NAME}-${1}"
docker run --user=10001 ${run_args} -d --cidfile=${cid_file} ${IMAGE_NAME}-${1}
info "Running docker run --user=10001 -P ${run_args} -d --cidfile=${cid_file} ${IMAGE_NAME}-${1}"
docker run --user=10001 -P ${run_args} -d --cidfile=${cid_file} ${IMAGE_NAME}-${1}
}

cleanup_test_app() {
Expand Down Expand Up @@ -221,12 +226,12 @@ test_for_output() {

test_connection() {
cat $cid_file
info "Testing the HTTP connection (http://$(container_ip):${test_port})"
info "Testing the HTTP connection (http://$(container_ip):$(test_port))"

if test_for_output "http://$(container_ip):${test_port}/" "NGINX is working" &&
test_for_output "http://$(container_ip):${test_port}/" "NGINX2 is working" localhost2 &&
test_for_output "http://$(container_ip):${test_port}/aliased/index2.html" "NGINX2 is working" &&
test_for_output "http://$(container_ip):${test_port}/nginx-cfg/default.conf" "404"; then
if test_for_output "http://$(container_ip):$(test_port)/" "NGINX is working" &&
test_for_output "http://$(container_ip):$(test_port)/" "NGINX2 is working" localhost2 &&
test_for_output "http://$(container_ip):$(test_port)/aliased/index2.html" "NGINX2 is working" &&
test_for_output "http://$(container_ip):$(test_port)/nginx-cfg/default.conf" "404"; then
return 0
fi

Expand All @@ -235,11 +240,11 @@ test_connection() {

test_connection_s2i() {
cat $cid_file
info "Testing the HTTP connection (http://$(container_ip):${test_port})"
info "Testing the HTTP connection (http://$(container_ip):$(test_port))"

if test_for_output "http://$(container_ip):${test_port}/" "NGINX is working" &&
test_for_output "http://$(container_ip):${test_port}/" "NGINX2 is working" localhost2 &&
test_for_output "http://$(container_ip):${test_port}/nginx-cfg/default.conf" "404"; then
if test_for_output "http://$(container_ip):$(test_port)/" "NGINX is working" &&
test_for_output "http://$(container_ip):$(test_port)/" "NGINX2 is working" localhost2 &&
test_for_output "http://$(container_ip):$(test_port)/nginx-cfg/default.conf" "404"; then
return 0
fi

Expand Down Expand Up @@ -291,15 +296,15 @@ test_log_output() {

info "Testing that GET / was logged as 200"

test_for_output "http://$(container_ip):${test_port}/" "NGINX is working"
test_for_output "http://$(container_ip):$(test_port)/" "NGINX is working"
check_result $? || return 1

test_logs '"GET / HTTP/1.1" 200' 'Test that GET / is logged as 200' stdout
check_result $? || return 1

info "Testing that GET /nothing-at-all was logged as 404"

test_for_output "http://$(container_ip):${test_port}/nothing-at-all" "404"
test_for_output "http://$(container_ip):$(test_port)/nothing-at-all" "404"
check_result $? || return 1

test_logs '"GET /nothing-at-all HTTP/1.1" 404' 'Test that bad GET is logged as 404' stdout
Expand All @@ -323,15 +328,15 @@ test_log_volume_output() {

info "Testing that GET / was logged as 200"

test_for_output "http://$(container_ip):${test_port}/" "NGINX is working"
test_for_output "http://$(container_ip):$(test_port)/" "NGINX is working"
check_result $? || return 1

test_logs '"GET / HTTP/1.1" 200' 'Test that GET / is logged as 200' /var/log/nginx/access.log
check_result $? || return 1

info "Testing that GET /nothing-at-all was logged as 404"

test_for_output "http://$(container_ip):${test_port}/nothing-at-all" "404"
test_for_output "http://$(container_ip):$(test_port)/nothing-at-all" "404"
check_result $? || return 1

test_logs '"GET /nothing-at-all HTTP/1.1" 404' 'Test that bad GET is logged as 404' /var/log/nginx/access.log
Expand All @@ -355,11 +360,11 @@ test_perl_directive() {
local perl_version=$(docker exec $(cat ${cid_file}) /bin/bash -c "perl -e 'print \"$^V\"'" 2>&1)

info "Testing perl_set directive sets header with perl version"
test_for_output "http://$(container_ip):${test_port}/" "X-Perl-Version: ${perl_version}"
test_for_output "http://$(container_ip):$(test_port)/" "X-Perl-Version: ${perl_version}"
check_result $? || return 1

info "Testing perl directive runs perl location handler"
test_for_output "http://$(container_ip):${test_port}/perl" "Perl location handler is working"
test_for_output "http://$(container_ip):$(test_port)/perl" "Perl location handler is working"
check_result $? || return 1

cleanup_test_app
Expand Down