REL-0.9 Adjust testing for new container

This commit is contained in:
cytopia 2017-05-11 09:16:24 +02:00
parent 73ab1b679d
commit cc8b93606a
No known key found for this signature in database
GPG Key ID: 6D56EDB8695128A2

View File

@ -56,7 +56,7 @@ runsu() {
printf "${_red}%s \$ ${_green}sudo ${_cmd}${_reset}\n" "${_user}"
fi
sudo "LANG=C LC_ALL=C ${_cmd}"
eval "sudo LANG=C LC_ALL=C ${_cmd}"
}
@ -148,21 +148,9 @@ get_data_mounts() {
###
### Default enabled Docker Versions
###
get_enabled_version_httpd() {
_default="$( grep -E '^HTTPD_SERVER=' "${DEVILBOX_PATH}/.env" | sed 's/^.*=//g' )"
echo "${_default}"
}
get_enabled_version_mysql() {
_default="$( grep -E '^MYSQL_SERVER=' "${DEVILBOX_PATH}/.env" | sed 's/^.*=//g' )"
echo "${_default}"
}
get_enabled_version_postgres() {
_default="$( grep -E '^POSTGRES_SERVER=' "${DEVILBOX_PATH}/.env" | sed 's/^.*=//g' )"
echo "${_default}"
}
get_enabled_version_php() {
_default="$( grep -E '^PHP_SERVER=' "${DEVILBOX_PATH}/.env" | sed 's/^.*=//g' )"
echo "${_default}"
get_enabled_versions() {
grep -E '^[A-Z]+_SERVER=' "${DEVILBOX_PATH}/.env" | sed 's/_SERVER=/\t/g'
}
@ -194,7 +182,7 @@ comment_all_dockers() {
# Comment out all enabled docker versions
run "sed -i'' \"s/^HTTPD_SERVER=/#HTTPD_SERVER=/g\" \"${DEVILBOX_PATH}/.env\""
run "sed -i'' \"s/^MYSQL_SERVER=/#MYSQL_SERVER=/g\" \"${DEVILBOX_PATH}/.env\""
run "sed -i'' \"s/^POSTGRES_SERVER=/#POSTGRES_SERVER=/g\" \"${DEVILBOX_PATH}/.env\""
run "sed -i'' \"s/^PGSQL_SERVER=/#PGSQL_SERVER=/g\" \"${DEVILBOX_PATH}/.env\""
run "sed -i'' \"s/^PHP_SERVER=/#PHP_SERVER=/g\" \"${DEVILBOX_PATH}/.env\""
}
@ -218,7 +206,7 @@ set_host_port_mysql() {
}
set_host_port_pgsql() {
_port="${1}"
run "sed -i'' \"s/^HOST_PORT_POSTGRES=.*/HOST_PORT_POSTGRES=${_port}/\" \"${DEVILBOX_PATH}/.env\""
run "sed -i'' \"s/^HOST_PORT_PGSQL=.*/HOST_PORT_PGSQL=${_port}/\" \"${DEVILBOX_PATH}/.env\""
}
###
@ -234,7 +222,7 @@ enable_docker_mysql() {
}
enable_docker_pgsql() {
_docker_version="${1}"
run "sed -i'' \"s/#POSTGRES_SERVER=${_docker_version}/POSTGRES_SERVER=${_docker_version}/g\" \"${DEVILBOX_PATH}/.env\""
run "sed -i'' \"s/#PGSQL_SERVER=${_docker_version}/PGSQL_SERVER=${_docker_version}/g\" \"${DEVILBOX_PATH}/.env\""
}
enable_docker_php() {
_docker_version="${1}"
@ -246,105 +234,48 @@ enable_docker_php() {
################################################################################
#
# S T A R T / S T O P T H E D E V I L B O X
# S T A R T / S T O P / T E S T T H E D E V I L B O X
#
################################################################################
devilbox_start() {
_srv1="${1}"
_ver1="${2}"
_srv2="${3}"
_ver2="${4}"
# Default values for remaining servers
_def_php="php-fpm-7.0"
_def_httpd="nginx-stable"
_def_mysql="mariadb-10.0"
_def_pgsql="9.6"
# Specific enabled servers
_set_php=""
_set_httpd=""
_set_mysql=""
_set_pgsql=""
_new_httpd="$1"
_new_mysql="$2"
_new_pysql="$3"
_new_php="$4"
_new_head="$5"
# Print Headline
print_h1 "${_srv1}-${_ver1} vs ${_srv2}-${_ver2}"
print_h1 "${_new_head}"
# Adjust .env
comment_all_dockers
# Enable Type 1
if [ "${_srv1}" = "HTTPD" ]; then
_set_httpd="${_ver1}"
elif [ "${_srv1}" = "MYSQL" ]; then
_set_mysql="${_ver1}"
elif [ "${_srv1}" = "PGSQL" ]; then
_set_pgsql="${_ver1}"
elif [ "${_srv1}" = "PHP" ]; then
_set_php="${_ver1}"
else
echo "Invalid server: ${_srv1}"
exit 1
fi
# Enable Type 2
if [ "${_srv2}" = "HTTPD" ]; then
_set_httpd="${_ver2}"
elif [ "${_srv2}" = "MYSQL" ]; then
_set_mysql="${_ver2}"
elif [ "${_srv2}" = "PGSQL" ]; then
_set_pgsql="${_ver2}"
elif [ "${_srv2}" = "PHP" ]; then
_set_php="${_ver2}"
else
echo "Invalid server: ${_srv2}"
exit 1
fi
# Enable remaining onces
if [ "${_set_php}" = "" ]; then
_set_php="${_def_php}"
fi
if [ "${_set_httpd}" = "" ]; then
_set_httpd="${_def_httpd}"
fi
if [ "${_set_mysql}" = "" ]; then
_set_mysql="${_def_mysql}"
fi
if [ "${_set_pgsql}" = "" ]; then
_set_pgsql="${_def_pgsql}"
fi
# Set versions in .env file
enable_docker_php "${_set_php}"
enable_docker_httpd "${_set_httpd}"
enable_docker_mysql "${_set_mysql}"
enable_docker_pgsql "${_set_pgsql}"
# Show Server settings
echo "Enable SERVERs"
echo "--------------"
grep '^[A-Za-z0-9]*_SERVER' "${DEVILBOX_PATH}/.env" | column -t -s '='
echo
# Show all other settings
echo "Enable Settings"
echo "---------------"
grep -E '^[-_A-Za-z0-9]*=' "${DEVILBOX_PATH}/.env" | grep -v 'SERVER_' | column -t -s '='
echo
enable_docker_httpd "${_new_httpd}"
enable_docker_mysql "${_new_mysql}"
enable_docker_pgsql "${_new_pysql}"
enable_docker_php "${_new_php}"
# Run
docker-compose up -d
# Wait for it to come up
wait_for 30 1
# Wait for http to return 200
printf "wait "
_max="90"
# shellcheck disable=SC2034
for i in $(seq 1 "${_max}"); do
if [ "$( curl --connect-timeout 1 --max-time 1 -s -o /dev/null -w '%{http_code}' http://localhost/index.php )" = "200" ]; then
break;
fi
sleep 1
printf "."
done
printf "\n"
# Show log/info
docker-compose logs
#docker-compose ps
# Wait another 30 sec for databases to come up
wait_for 30 1
echo
}
devilbox_stop() {
# Stop existing dockers
cd "${DEVILBOX_PATH}" || exit 1
@ -358,10 +289,34 @@ devilbox_stop() {
IFS='
'
for d in ${_data_dirs}; do
runsu "rm -rf ${d}"
runsu "rm -rf ${d}" "1"
done
}
devilbox_show() {
###
### 1. Show Info
###
print_h2 "Info"
# Show wanted versions
echo "[Wanted] .env settings"
echo "------------------------------------------------------------"
get_enabled_versions
echo
# Get actual versions
echo "[Actual] http://localhost settings"
echo "------------------------------------------------------------"
curl -q http://localhost/index.php 2>/dev/null | \
grep -E 'circles' | \
grep -oE '<strong.*strong>.*\(.*\)' | \
sed 's/<strong>//g' | \
sed 's/<\/strong>.*(/\t/g' | \
sed 's/)//g'
echo
}
################################################################################
#
@ -369,40 +324,20 @@ devilbox_stop() {
#
################################################################################
debilbox_test() {
###
### Variables
###
_ret=0 # Final exit code
_oks=4 # Require this many [OK]'s on the page
_oks=17 # Require this many [OK]'s on the page
###
### 1. Show Info
###
print_h2 "1. Info"
# Show wanted versions
echo ".env settings"
echo "------------------------------------------------------------"
echo "HTTPD: $(get_enabled_version_httpd)"
echo "PHP: $(get_enabled_version_php)"
echo "MySQL: $(get_enabled_version_mysql)"
echo "PgSQL: $(get_enabled_version_postgres)"
echo
# Get actual versions
echo "http://localhost settings"
echo "------------------------------------------------------------"
curl -q http://localhost/index.php 2>/dev/null | grep -E '<h3>.*</h3>' | sed 's/.*<h3>//g' | sed 's/<\/h3>//g'
echo
###
### 2. Test docker-compose
###
print_h2 "2. docker-compose"
print_h2 "docker-compose"
echo "docker-compose ps"
echo "------------------------------------------------------------"
@ -421,11 +356,21 @@ debilbox_test() {
echo "Count [OK]'s on curl-ed url"
echo "------------------------------------------------------------"
if _cnt="$( _test_curled_oks "${_oks}" )"; then
echo "[OK]: ${_cnt} of ${_oks}"
else
echo "[ERR]: ${_cnt} of ${_oks}"
if ! _cnt="$( _test_curled_oks "${_oks}" )"; then
_ret="$(( _ret + 1 ))"
echo "[ERR]: ${_cnt} / ${_oks} (Not all 'dvlbox-ok' found)"
else
echo "[OK]: ${_cnt} / ${_oks} (All 'dvlbox-ok' found)"
fi
echo
echo "Count [ERR]'s on curl-ed url"
echo "------------------------------------------------------------"
if ! _cnt="$( _test_curled_err )"; then
_ret="$(( _ret + 1 ))"
echo "[ERR]: ${_cnt} / 0 (Found some 'dvlbox-err')"
else
echo "[OK]: ${_cnt} / 0 (No 'dvlbox-err' found)"
fi
echo
@ -456,14 +401,19 @@ debilbox_test() {
sudo find log -type f -exec sh -c 'echo "{}:\n-----------------"; cat "{}"; echo "\n\n"' \;
return 1
fi
return 0
}
################################################################################
#
# T E S T I N G H E L P E R
#
################################################################################
###
### Test against stopped containers
###
@ -490,20 +440,9 @@ _test_docker_compose() {
###
_test_curled_oks() {
_oks="${1}"
_find_ok="dvlbox-ok"
max="20"
i=0
while [ $i -lt $max ]; do
if [ "$( curl -s -o /dev/null -w '%{http_code}' http://localhost/index.php )" != "404" ]; then
break;
fi
sleep 1s
i=$(( i + 1 ))
done
# sleep (in case hhvm segfaulted and needs to be restarted)
sleep 10
_count="$( curl -q http://localhost/index.php 2>/dev/null | grep -c 'OK' || true )"
_count="$( curl -q http://localhost/index.php 2>/dev/null | grep -c "${_find_ok}" || true )"
echo "${_count}"
if [ "${_count}" != "${_oks}" ]; then
@ -512,3 +451,19 @@ _test_curled_oks() {
return 0
fi
}
###
### Test [ERR]'s found on website
###
_test_curled_err() {
_find_err="dvlbox-err"
_count="$( curl -q http://localhost/index.php 2>/dev/null | grep -c "${_find_err}" || true )"
echo "${_count}"
if [ "${_count}" != "0" ]; then
return 1
else
return 0
fi
}