devilbox/.tests/tests/intranet-memcached.sh
2019-11-18 00:17:10 +01:00

64 lines
2.0 KiB
Bash
Executable File

#!/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=()
echo
echo "# --------------------------------------------------------------------------------------------------"
echo "# [Intranet] Memcached"
echo "# --------------------------------------------------------------------------------------------------"
echo
# -------------------------------------------------------------------------------------------------
# Pre-check
# -------------------------------------------------------------------------------------------------
PHP_SERVER="$( "${SCRIPT_PATH}/../scripts/env-getvar.sh" "PHP_SERVER" )"
if [[ ${DISABLED_VERSIONS[*]} =~ ${PHP_SERVER} ]]; then
printf "[SKIP] Skipping all checks for PHP %s\\n" "${PHP_SERVER}"
exit 0
fi
if ! command -v curl >/dev/null 2>&1; then
>&2 echo "Error 'curl' binary not found, but required."
exit 1
fi
if ! command -v tac >/dev/null 2>&1; then
>&2 echo "Error 'tac' binary not found, but required."
exit 1
fi
# -------------------------------------------------------------------------------------------------
# ENTRYPOINT
# -------------------------------------------------------------------------------------------------
###
### Get required env values
###
HOST_PORT_HTTPD="$( "${SCRIPT_PATH}/../scripts/env-getvar.sh" "HOST_PORT_HTTPD" )"
printf "[TEST] devilbox-version key in Memcached"
if ! run "curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}/db_memcd.php' | tac | tac | grep -q 'devilbox-version'" "${RETRIES}" "" "0"; then
printf "\\r[FAIL] devilbox-version key in Memcached\\n"
run "curl 'http://localhost:${HOST_PORT_HTTPD}/db_memcd.php' || true"
exit 1
else
printf "\\r[OK] devilbox-version key in Memcached\\n"
fi