devilbox/.tests/tests/vendor-phpredmin.sh

85 lines
2.5 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# NOTE: Parsing curl to tac to circumnvent "failed writing body"
# https://stackoverflow.com/questions/16703647/why-curl-return-and-error-23-failed-writing-body
set -e
set -u
set -o pipefail
SCRIPT_PATH="$( cd "$(dirname "$0")" && pwd -P )"
DVLBOX_PATH="$( cd "${SCRIPT_PATH}/../.." && pwd -P )"
# shellcheck disable=SC1090
. "${SCRIPT_PATH}/../scripts/.lib.sh"
RETRIES=10
DISABLED_VERSIONS=("5.2" "5.3" "5.4")
echo
echo "# --------------------------------------------------------------------------------------------------"
2019-11-21 08:43:00 +00:00
echo "# [Vendor] phpRedmin"
echo "# --------------------------------------------------------------------------------------------------"
echo
# -------------------------------------------------------------------------------------------------
2019-11-21 08:43:00 +00:00
# Pre-check
# -------------------------------------------------------------------------------------------------
2019-11-21 08:43:00 +00:00
PHP_VERSION="$( get_php_version "${DVLBOX_PATH}" )"
if [[ ${DISABLED_VERSIONS[*]} =~ ${PHP_VERSION} ]]; then
printf "[SKIP] Skipping all checks for PHP %s\\n" "${PHP_VERSION}"
exit 0
fi
2019-11-21 08:43:00 +00:00
# -------------------------------------------------------------------------------------------------
# ENTRYPOINT
# -------------------------------------------------------------------------------------------------
###
2019-11-21 08:43:00 +00:00
### Get required env values
###
2019-11-21 08:43:00 +00:00
HOST_PORT_HTTPD="$( "${SCRIPT_PATH}/../scripts/env-getvar.sh" "HOST_PORT_HTTPD" )"
###
2019-11-21 08:43:00 +00:00
### Ensure PHPRedmin works
###
2019-11-21 08:43:00 +00:00
URL="/vendor/phpredmin/public/index.php"
printf "[TEST] Fetch %s" "${URL}"
if [ "$( run "\
curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}${URL}' \
| tac \
| tac \
| grep -Ec 'Strings|Hashes|Lists|Sets|Sorted Sets'" \
"${RETRIES}" "" "0" )" != "5" ]; then
printf "\\r[FAIL] Fetch %s\\n" "${URL}"
run "curl -sS 'http://localhost:${HOST_PORT_HTTPD}${URL}' || true"
run "curl -sS -I 'http://localhost:${HOST_PORT_HTTPD}${URL}' || true"
exit 1
else
printf "\\r[OK] Fetch %s\\n" "${URL}"
fi
###
### Ensure PHPRedmin works in subdirectory
###
URL="/vendor/phpredmin/public/index.php/welcome/info/0/0"
2019-11-21 08:43:00 +00:00
printf "[TEST] Fetch %s" "${URL}"
if [ "$( run "\
curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}${URL}' \
| tac \
| tac \
| grep -Ec '(Version:)|(Mode:)|(Role:)|(OS:)|(Uptime:)'" \
"${RETRIES}" "" "0" )" != "5" ]; then
printf "\\r[FAIL] Fetch %s\\n" "${URL}"
run "curl -sS 'http://localhost:${HOST_PORT_HTTPD}${URL}' || true"
run "curl -sS -I 'http://localhost:${HOST_PORT_HTTPD}${URL}' || true"
exit 1
else
2019-11-21 08:43:00 +00:00
printf "\\r[OK] Fetch %s\\n" "${URL}"
fi