From 56672eec236e0024f3f73e6b0f935a5cf1e5aa4d Mon Sep 17 00:00:00 2001 From: cytopia Date: Sun, 9 Dec 2018 01:55:12 +0100 Subject: [PATCH] Replace test scripts with Makefile --- .tests/.lib.sh | 453 ------------------- .tests/Makefile | 464 ++++++++++++++++++++ .tests/README.md | 47 ++ .tests/intra-tests/README.md | 4 + .tests/intra-tests/homepage.sh | 64 +++ .tests/test_single.sh | 147 ------- .tests/vhost-tests/README.md | 7 + .tests/vhost-tests/htdocs/intranet-mail.php | 46 ++ .tests/vhost-tests/htdocs/memcached.php | 59 +++ .tests/vhost-tests/htdocs/mongodb.php | 39 ++ .tests/vhost-tests/htdocs/mysql.php | 44 ++ .tests/vhost-tests/htdocs/postgres.php | 40 ++ .tests/vhost-tests/htdocs/redis.php | 40 ++ .travis.yml | 41 +- 14 files changed, 879 insertions(+), 616 deletions(-) delete mode 100644 .tests/.lib.sh create mode 100644 .tests/Makefile create mode 100644 .tests/README.md create mode 100644 .tests/intra-tests/README.md create mode 100755 .tests/intra-tests/homepage.sh delete mode 100755 .tests/test_single.sh create mode 100644 .tests/vhost-tests/README.md create mode 100644 .tests/vhost-tests/htdocs/intranet-mail.php create mode 100644 .tests/vhost-tests/htdocs/memcached.php create mode 100644 .tests/vhost-tests/htdocs/mongodb.php create mode 100644 .tests/vhost-tests/htdocs/mysql.php create mode 100644 .tests/vhost-tests/htdocs/postgres.php create mode 100644 .tests/vhost-tests/htdocs/redis.php diff --git a/.tests/.lib.sh b/.tests/.lib.sh deleted file mode 100644 index 29e16f8b..00000000 --- a/.tests/.lib.sh +++ /dev/null @@ -1,453 +0,0 @@ -#!/bin/sh -eu - - -DEVILBOX_PATH="$( echo "${1}"| sed 's/\/*$//' )" # remove last slash(es): / - - - -################################################################################ -# -# H E L P E R -# -################################################################################ - -run() { - _cmd="${1}" - _debug="0" - - _red="\033[0;31m" - _green="\033[0;32m" - _reset="\033[0m" - _user="$(whoami)" - - - # If 2nd argument is set and enabled, allow debug command - if [ "${#}" = "2" ]; then - if [ "${2}" = "1" ]; then - _debug="1" - fi - fi - - - if [ "${_debug}" = "1" ]; then - printf "${_red}%s \$ ${_green}${_cmd}${_reset}\n" "${_user}" - fi - sh -c "LANG=C LC_ALL=C ${_cmd}" -} - -runsu() { - _cmd="${1}" - _debug="0" - - _red="\033[0;31m" - _green="\033[0;32m" - _reset="\033[0m" - _user="$(whoami)" - - # If 2nd argument is set and enabled, allow debug command - if [ "${#}" = "2" ]; then - if [ "${2}" = "1" ]; then - _debug="1" - fi - fi - - - if [ "${_debug}" = "1" ]; then - printf "${_red}%s \$ ${_green}sudo ${_cmd}${_reset}\n" "${_user}" - fi - - eval "sudo LANG=C LC_ALL=C ${_cmd}" -} - -print_h1() { - _headline="${1}" - - _blue="\033[0;34m" - _reset="\033[0m" - printf "${_blue}%s${_reset}\n" "################################################################################" - printf "${_blue}%s${_reset}\n" "#" - printf "${_blue}%s %s${_reset}\n" "#" "${_headline}" - printf "${_blue}%s${_reset}\n" "#" - printf "${_blue}%s${_reset}\n" "################################################################################" -} - -print_h2() { - _headline="${1}" - - _blue="\033[0;34m" - _reset="\033[0m" - printf "${_blue}%s${_reset}\n" "############################################################" - printf "${_blue}%s %s${_reset}\n" "#" "${_headline}" - printf "${_blue}%s${_reset}\n" "############################################################" -} - -wait_for() { - _time="${1}" - _debug="0" - - - # Sleep with debug output - if [ "${#}" = "2" ]; then - if [ "${2}" = "1" ]; then - printf "wait " - # shellcheck disable=SC2034 - for i in $(seq 1 "${_time}"); do - sleep 1 - printf "." - done - printf "\n" - return 0 - fi - fi - - - # Sleep silently - sleep "${_time}" -} - - -################################################################################ -# -# G E T D E F A U L T S -# -################################################################################ - -### -### Get newline separated default data mount directories (from .env file) -### -get_data_mounts() { - _mounts="$( grep -E '^.*_DATADIR=' "${DEVILBOX_PATH}/env-example" | sed 's/^.*=//g' )" - _data="" - - IFS=' - ' - for _mount in ${_mounts}; do - _prefix="$( echo "${_mount}" | cut -c-1 )" - - # Relative path? - if [ "${_prefix}" = "." ]; then - _mount="$( echo "${_mount}" | sed 's/^\.//g' )" # Remove leading dot: . - _mount="$( echo "${_mount}" | sed 's/^\///' )" # Remove leading slash: / - _mount="${DEVILBOX_PATH}/${_mount}" - fi - - # newline Append - if [ "${_data}" = "" ]; then - _data="${_mount}" - else - _data="${_data}\n${_mount}" - fi - done - - echo "${_data}" -} - - - -################################################################################ -# -# S E T / R E S E T F U N C T I O N S -# -################################################################################ - -### -### Recreate .env file from env-example -### -reset_env_file() { - - # Re-create .env file - if [ -f "${DEVILBOX_PATH}/.env" ]; then - rm -f "${DEVILBOX_PATH}/.env" - fi - cp "${DEVILBOX_PATH}/env-example" "${DEVILBOX_PATH}/.env" -} - -### -### Comment out all docker versions -### -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/^PGSQL_SERVER=/#PGSQL_SERVER=/g\" \"${DEVILBOX_PATH}/.env\"" - run "sed -i'' \"s/^PHP_SERVER=/#PHP_SERVER=/g\" \"${DEVILBOX_PATH}/.env\"" -} - -### -### Enable debug mode -### -set_debug_enable() { - run "sed -i'' \"s/^DEBUG_COMPOSE_ENTRYPOINT=.*/DEBUG_COMPOSE_ENTRYPOINT=1/\" \"${DEVILBOX_PATH}/.env\"" -} - -### -### Alter ports -### -set_host_port_httpd() { - _port="${1}" - run "sed -i'' \"s/^HOST_PORT_HTTPD=.*/HOST_PORT_HTTPD=${_port}/\" \"${DEVILBOX_PATH}/.env\"" -} -set_host_port_mysql() { - _port="${1}" - run "sed -i'' \"s/^HOST_PORT_MYSQL=.*/HOST_PORT_MYSQL=${_port}/\" \"${DEVILBOX_PATH}/.env\"" -} -set_host_port_pgsql() { - _port="${1}" - run "sed -i'' \"s/^HOST_PORT_PGSQL=.*/HOST_PORT_PGSQL=${_port}/\" \"${DEVILBOX_PATH}/.env\"" -} - -### -### Eenable desired docker version -### -enable_docker_httpd() { - _docker_version="${1}" - run "sed -i'' \"s/#HTTPD_SERVER=${_docker_version}/HTTPD_SERVER=${_docker_version}/g\" \"${DEVILBOX_PATH}/.env\"" -} -enable_docker_mysql() { - _docker_version="${1}" - run "sed -i'' \"s/#MYSQL_SERVER=${_docker_version}/MYSQL_SERVER=${_docker_version}/g\" \"${DEVILBOX_PATH}/.env\"" -} -enable_docker_pgsql() { - _docker_version="${1}" - run "sed -i'' \"s/#PGSQL_SERVER=${_docker_version}/PGSQL_SERVER=${_docker_version}/g\" \"${DEVILBOX_PATH}/.env\"" -} -enable_docker_php() { - _docker_version="${1}" - run "sed -i'' \"s/#PHP_SERVER=${_docker_version}/PHP_SERVER=${_docker_version}/g\" \"${DEVILBOX_PATH}/.env\"" -} - - - -################################################################################ -# -# S T A R T / S T O P T H E D E V I L B O X -# -################################################################################ - -devilbox_configure() { - _srv1="${1}" - _ver1="${2}" - _srv2="${3}" - _ver2="${4}" - - # Default values for remaining servers - _def_php="${5}" - _def_httpd="${6}" - _def_mysql="${7}" - _def_pgsql="${8}" - - # Specific enabled servers - _set_php="" - _set_httpd="" - _set_mysql="" - _set_pgsql="" - - # 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 - - # Adjust .env - comment_all_dockers - - # 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}" -} - - -devilbox_configured_settings() { - grep -E '^[A-Z]+_SERVER=' "${DEVILBOX_PATH}/.env" | sed 's/_SERVER=/\t/g' -} - - -devilbox_pull() { - # Make sure to pull until success - ret=1 - while [ "${ret}" != "0" ]; do - if ! docker-compose pull; then - ret=1 - else - ret=0 - fi - done -} - - -devilbox_start() { - # Make sure everything is stopped and defaulted - sudo service docker restart || true - sleep 5 - devilbox_stop - - # Make sure to start until success - ret=1 - while [ "${ret}" != "0" ]; do - if ! docker-compose up -d; then - ret=1 - # Stop it and try again - devilbox_stop - else - ret=0 - fi - done - - # 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://127.0.0.1/index.php )" = "200" ]; then - break; - fi - sleep 1 - printf "." - done - printf "\n" - - # Wait another 60 sec for databases to come up - wait_for 60 1 - echo - -} - - -devilbox_print_actual_settings() { - VERSIONS="$( curl -q http://127.0.0.1/index.php 2>/dev/null | \ - grep -E 'circles' | \ - grep -oE '.*\(.*\)' | \ - sed 's///g' | \ - sed 's/<\/strong>.*(/\t/g' | \ - sed 's/)//g' )" - - IFS=' -' - for v in ${VERSIONS}; do - service="$( echo "${v}" | awk '{print $1}' )" - version="$( echo "${v}" | awk '{print $2}' )" - printf "%-15s%s\n" "${service}" "${version}" - done -} - - -devilbox_stop() { - # Stop existing dockers - cd "${DEVILBOX_PATH}" || exit 1 - docker-compose down > /dev/null 2>&1 || true - docker-compose stop > /dev/null 2>&1 || true - docker-compose kill > /dev/null 2>&1 || true - docker-compose rm -f || true - - # Delete existing data dirs - _data_dirs="$( get_data_mounts )" - IFS=' - ' - for d in ${_data_dirs}; do - runsu "rm -rf ${d}" "1" - done -} - - -devilbox_print_errors() { - _url="${1}" - - print_h2 "[ERROR] Curl" - curl -vv "${_url}" || true - echo - - print_h2 "[ERROR] docker-compose ps" - docker-compose ps - echo - - print_h2 "[ERROR] docker-compose logs" - docker-compose logs - echo - - print_h2 "[ERROR] log files" - ls -lap log/ - sudo find log -type f -exec sh -c 'echo "{}:\n-----------------"; cat "{}"; echo "\n\n"' \; -} - -################################################################################ -# -# T E S T T H E D E V I L B O X -# -################################################################################ - -devilbox_test_compose() { - - _broken="$( docker-compose ps | grep -c 'Exit' || true )" - _running="$( docker-compose ps | grep -c 'Up' || true )" - _total="$( docker-compose ps -q | grep -c '' || true )" - - if [ "${_broken}" != "0" ]; then - echo "[ERR]: Broken: ${_broken} broken container" - return 1 - fi - - if [ "${_running}" != "${_total}" ]; then - echo "[ERR]: Broken: ${_running} / ${_total} container running" - return 1 - fi - - echo "[OK]: All running" - return 0 -} - - -devilbox_test_url() { - # Variables - _url="${1}" - _pattern="${2}" - _number="${3}" - - _count="$( curl -q --retry 100 --retry-max-time 0 "${_url}" 2>/dev/null | grep -c "${_pattern}" || true )" - - if [ "${_count}" != "${_number}" ]; then - echo "[ERR]: Found ${_count}/${_number} of '${_pattern}'" - return 1 - fi - - echo "[OK]: Found ${_count}/${_number} of '${_pattern}'" - return 0 -} diff --git a/.tests/Makefile b/.tests/Makefile new file mode 100644 index 00000000..ea733ab1 --- /dev/null +++ b/.tests/Makefile @@ -0,0 +1,464 @@ +# ------------------------------------------------------------------------------------------------- +# Settings +# ------------------------------------------------------------------------------------------------- + +SHELL := /bin/bash + + +# ------------------------------------------------------------------------------------------------- +# Variables +# ------------------------------------------------------------------------------------------------- + +# Paths and directory names +CURRENT_PATH = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) +DEVILBOX_PATH = $(CURRENT_PATH).. +DEVILBOX_NAME = $(shell cd $(DEVILBOX_PATH); basename $$(pwd)) + +# Docker +DOCKER_NETWORK = $(shell docker network ls --filter name='$(DEVILBOX_NAME)' --quiet) + +# Devilbox test settings +PROJECT = vhost-tests +VHOST = $(PROJECT).loc + + +# ------------------------------------------------------------------------------------------------- +# Testing Targets +# ------------------------------------------------------------------------------------------------- + +### +### Initialize .env file and data dir +### +init: + @echo "####################################################################################################" + @echo "# INITIALIZING .env FILE" + @echo "####################################################################################################" + $(eval MY_UID := $(shell id -u)) + $(eval MY_GID := $(shell id -g)) + + @# Ensure .env file exists + install -m 0644 $(DEVILBOX_PATH)/env-example $(DEVILBOX_PATH)/.env + @# Set bind port + echo "HOST_PORT_BIND=53" >> $(DEVILBOX_PATH)/.env + @# Set data dir + sed -i'' 's/^HOST_PATH_HTTPD_DATADIR=/#HOST_PATH_HTTPD_DATADIR=/g' $(DEVILBOX_PATH)/.env + echo "HOST_PATH_HTTPD_DATADIR=.tests" >> $(DEVILBOX_PATH)/.env + @# Set uid/gid + sed -i'' 's/^NEW_UID=.*/NEW_UID=$(MY_UID)/g' $(DEVILBOX_PATH)/.env + sed -i'' 's/^NEW_GID=.*/NEW_GID=$(MY_GID)/g' $(DEVILBOX_PATH)/.env + @echo + + +### +### Configure custom versions +### +configure: +ifdef SRV +ifdef VER + sed -i'' 's/^$(SRV)/#$(SRV)/g' $(DEVILBOX_PATH)/.env + echo "$(SRV)=$(VER)" >> $(DEVILBOX_PATH)/.env +endif +endif + + +### +### Start Devilbox +### +start: stop pull + @echo "####################################################################################################" + @echo "# STARTING CONTAINER" + @echo "####################################################################################################" + cd $(DEVILBOX_PATH) && docker-compose up -d + @$(MAKE) _wait + @echo + + +### +### Pulling latest container +### +pull: + @echo "####################################################################################################" + @echo "# PULLING LATEST CONTAINER" + @echo "####################################################################################################" + cd $(DEVILBOX_PATH) && docker-compose pull + @echo + @echo + + +### +### Stop Devilbox +### +stop: + @echo "####################################################################################################" + @echo "# STOPPING CONTAINER" + @echo "####################################################################################################" + cd $(DEVILBOX_PATH) && docker-compose stop || true + cd $(DEVILBOX_PATH) && docker-compose kill || true + cd $(DEVILBOX_PATH) && docker-compose rm -f || true + @echo + + +### +### Get Info +### +info: + @echo "####################################################################################################" + @echo "# CONTAINER INFO" + @echo "####################################################################################################" + + $(eval DOCKER := $(shell docker --version)) + $(eval COMPOSE := $(shell docker-compose --version)) + + $(eval BIND := $(shell curl -sS localhost/index.php | grep -Ei 'bg-info.*Bind' | grep -Eo '\(.+?\)' | sed -e 's/(//g' -e 's/)//g')) + $(eval PHP := $(shell curl -sS localhost/index.php | grep -Ei 'bg-info.*PHP' | grep -Eo '\(.+?\)' | sed -e 's/(//g' -e 's/)//g')) + $(eval HTTPN := $(shell curl -sS localhost/index.php | grep -Ei 'bg-info.*(nginx|apache)' | grep -Eio 'nginx|apache')) + $(eval HTTPV := $(shell curl -sS localhost/index.php | grep -Ei 'bg-info.*(nginx|apache)' | grep -Eo '\(.+?\)' | sed -e 's/(//g' -e 's/)//g')) + $(eval MYSQLN := $(shell curl -sS localhost/index.php | grep -Ei 'bg-warn.*(mysql|maria|percona)' | grep -Eio 'mysql|maria|percona')) + $(eval MYSQLV := $(shell curl -sS localhost/index.php | grep -Ei 'bg-warn.*(mysql|maria|percona)' | grep -Eo '\(.+?\)' | sed -e 's/(//g' -e 's/)//g')) + $(eval PGSQL := $(shell curl -sS localhost/index.php | grep -Ei 'bg-warn.*Postgre' | grep -Eo '\(.+?\)' | sed -e 's/(//g' -e 's/)//g')) + $(eval REDIS := $(shell curl -sS localhost/index.php | grep -Ei 'bg-dang.*Redis' | grep -Eo '\(.+?\)' | sed -e 's/(//g' -e 's/)//g')) + $(eval MEMCD := $(shell curl -sS localhost/index.php | grep -Ei 'bg-dang.*Memcached' | grep -Eo '\(.+?\)' | sed -e 's/(//g' -e 's/)//g')) + $(eval MONGO := $(shell curl -sS localhost/index.php | grep -Ei 'bg-dang.*Mongo' | grep -Eo '\(.+?\)' | sed -e 's/(//g' -e 's/)//g')) + + @echo "Docker: $(DOCKER)" + @echo "Compose: $(COMPOSE)" + @echo "Bind: $(BIND)" + @echo "PHP: $(PHP)" + @echo "HTTPD: $(HTTPN) $(HTTPV)" + @echo "MYSQL: $(MYSQLN) $(MYSQLV)" + @echo "PGSQL: $(PGSQL)" + @echo "Redis: $(REDIS)" + @echo "Memcd: $(MEMCD)" + @echo "Mongo: $(MONGO)" + @echo + + +### +### Run tests +### +test: test-vhost test-intra + +test-intra: + @echo "####################################################################################################" + @echo "# RUNNING TESTS: INTRANET" + @echo "####################################################################################################" + @echo + + @# Gather files to test + $(eval SH_FILES := $(notdir $(wildcard $(CURRENT_PATH)/intra-tests/*.sh))) + + @$(foreach file,\ + $(SH_FILES), \ + echo "# ----------------------------------------------------------------------------------------"; \ + echo "# [intra] $(file)"; \ + echo "# ----------------------------------------------------------------------------------------"; \ + cd $(CURRENT_PATH) && $(MAKE) _clean-round >/dev/null; \ + if ! $(CURRENT_PATH)/intra-tests/$(file); then \ + cd $(CURRENT_PATH) && $(MAKE) _logs; \ + exit 1; \ + fi; \ + echo; \ + ) + @echo + + +test-vhost: + @echo "####################################################################################################" + @echo "# RUNNING TESTS: VHOST" + @echo "####################################################################################################" + @echo + + @# Required to test against apache-2.(2|4) + $(eval HTTPD_SERVER := $(shell grep -E '^HTTPD_SERVER' $(DEVILBOX_PATH)/.env | sed 's/.*=//g')) + + @# Gather files to test + $(eval PHP_FILES := $(notdir $(wildcard $(CURRENT_PATH)/$(PROJECT)/htdocs/*.php))) + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [vhost] Test curl HTTP from Docker host" + @echo "# ----------------------------------------------------------------------------------------" + @$(foreach file,\ + $(PHP_FILES), \ + printf "[TEST] curl -sS --header 'Host: $(VHOST)' http://localhost/$(file)"; \ + cd $(CURRENT_PATH) && $(MAKE) _clean-round >/dev/null; \ + if ! curl -sS --header 'Host: $(VHOST)' http://localhost/$(file) | grep -qE '^OK$$'; then \ + printf "\r[FAIL] curl -sS --header 'Host: $(VHOST)' http://localhost/$(file)\n"; \ + curl -sS --header 'Host: $(VHOST)' http://localhost/$(file); \ + curl -sS -I --header 'Host: $(VHOST)' http://localhost/$(file); \ + cd $(CURRENT_PATH) && $(MAKE) _logs; \ + exit 1; \ + else \ + printf "\r[OK] curl -sS --header 'Host: $(VHOST)' http://localhost/$(file)\n"; \ + fi; \ + ) + @echo + + @# Error: Hostname localhost provided via SNI and hostname vhost-tests.loc provided via HTTP are different + @# @echo "# ----------------------------------------------------------------------------------------" + @# @echo "# [vhost] Test curl HTTPS from Docker host" + @# @echo "# ----------------------------------------------------------------------------------------" + @# @$(foreach file,\ + @# $(PHP_FILES), \ + @# printf "[TEST] curl -k -sS --header 'Host: $(VHOST)' https://localhost/$(file)"; \ + @# cd $(CURRENT_PATH) && $(MAKE) _clean-round >/dev/null; \ + @# if ! curl -k -sS --header 'Host: $(VHOST)' https://localhost/$(file) | grep -qE '^OK$$'; then \ + @# printf "\r[FAIL] curl -k -sS --header 'Host: $(VHOST)' https://localhost/$(file)\n"; \ + @# curl -k -sS --header 'Host: $(VHOST)' https://localhost/$(file); \ + @# curl -k -sS -I --header 'Host: $(VHOST)' https://localhost/$(file); \ + @# cd $(CURRENT_PATH) && $(MAKE) _logs; \ + @# exit 1; \ + @# else \ + @# printf "\r[OK] curl -k -sS --header 'Host: $(VHOST)' https://localhost/$(file)\n"; \ + @# fi; \ + @# ) + @# @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [vhost] Test curl HTTP from inside Docker container" + @echo "# ----------------------------------------------------------------------------------------" + @$(foreach file,\ + $(PHP_FILES), \ + printf "[TEST] docker-compose exec php curl -sS http://$(VHOST)/$(file)"; \ + cd $(CURRENT_PATH) && $(MAKE) _clean-round >/dev/null; \ + if ! cd $(DEVILBOX_PATH) && docker-compose exec php curl -sS http://$(VHOST)/$(file) | grep -qE '^OK$$'; then \ + printf "\r[FAIL] docker-compose exec php curl -sS http://$(VHOST)/$(file)\n"; \ + cd $(DEVILBOX_PATH) && docker-compose exec php curl -sS http://$(VHOST)/$(file); \ + cd $(DEVILBOX_PATH) && docker-compose exec php curl -sS -I http://$(VHOST)/$(file); \ + cd $(CURRENT_PATH) && $(MAKE) _logs; \ + exit 1; \ + else \ + printf "\r[OK] docker-compose exec php curl -sS http://$(VHOST)/$(file)\n"; \ + fi; \ + ) + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [vhost] Test curl HTTPS from inside Docker container" + @echo "# ----------------------------------------------------------------------------------------" + @$(foreach file,\ + $(PHP_FILES), \ + printf "[TEST] docker-compose exec php curl -sS https://$(VHOST)/$(file)"; \ + cd $(CURRENT_PATH) && $(MAKE) _clean-round >/dev/null; \ + if ! cd $(DEVILBOX_PATH) && docker-compose exec php curl -sS https://$(VHOST)/$(file) | grep -qE '^OK$$'; then \ + printf "\r[FAIL] docker-compose exec php curl -sS https://$(VHOST)/$(file)\n"; \ + cd $(DEVILBOX_PATH) && docker-compose exec php curl -sS https://$(VHOST)/$(file); \ + cd $(DEVILBOX_PATH) && docker-compose exec php curl -sS -I https://$(VHOST)/$(file); \ + cd $(CURRENT_PATH) && $(MAKE) _logs; \ + exit 1; \ + else \ + printf "\r[OK] docker-compose exec php curl -sS https://$(VHOST)/$(file)\n"; \ + fi; \ + ) + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [vhost] Test php-cli from inside Docker container" + @echo "# ----------------------------------------------------------------------------------------" + @$(foreach file,\ + $(PHP_FILES), \ + printf "[TEST] docker-compose exec php php /shared/httpd/$(PROJECT)/htdocs/$(file)"; \ + cd $(CURRENT_PATH) && $(MAKE) _clean-round >/dev/null; \ + if ! cd $(DEVILBOX_PATH) && docker-compose exec php php /shared/httpd/$(PROJECT)/htdocs/$(file) | grep -q '^OK$$'; then \ + printf "\r[TEST] docker-compose exec php php /shared/httpd/$(PROJECT)/htdocs/$(file)\n"; \ + cd $(DEVILBOX_PATH) && docker-composeexec php php /shared/httpd/$(PROJECT)/htdocs/$(file); \ + cd $(CURRENT_PATH) && $(MAKE) _logs; \ + exit 1; \ + else \ + printf "\r[OK] docker-compose exec php php /shared/httpd/$(PROJECT)/htdocs/$(file)\n"; \ + fi; \ + ) + @echo + + +# ------------------------------------------------------------------------------------------------- +# Helper Targets +# ------------------------------------------------------------------------------------------------- + +# TODO: this is super slow and should better be replaced by using local files instead +_clean-round: + $(eval HTTPD_SERVER := $(shell grep -E '^HTTPD_SERVER' $(DEVILBOX_PATH)/.env | sed 's/.*=//g')) + $(eval PHP_SERVER := $(shell grep -E '^PHP_SERVER' $(DEVILBOX_PATH)/.env | sed 's/.*=//g')) + + @> $(DEVILBOX_PATH)/mail/devilbox + + @> $(DEVILBOX_PATH)/log/php-fpm-$(PHP_SERVER)/php-fpm.access + @> $(DEVILBOX_PATH)/log/php-fpm-$(PHP_SERVER)/php-fpm.error + + @#cd $(DEVILBOX_PATH) && docker-compose exec httpd dd if=/dev/null of=/var/log/$(HTTPD_SERVER)/defaultlocalhost-access.log >/dev/null 2>&1 || true + @#cd $(DEVILBOX_PATH) && docker-compose exec httpd dd if=/dev/null of=/var/log/$(HTTPD_SERVER)/defaultlocalhost-error.log >/dev/null 2>&1 || true + @#cd $(DEVILBOX_PATH) && docker-compose exec httpd dd if=/dev/null of=/var/log/$(HTTPD_SERVER)/defaultlocalhost_ssl-access.log >/dev/null 2>&1 || true + @#cd $(DEVILBOX_PATH) && docker-compose exec httpd dd if=/dev/null of=/var/log/$(HTTPD_SERVER)/defaultlocalhost_ssl-error.log >/dev/null 2>&1 || true + + @#cd $(DEVILBOX_PATH) && docker-compose exec httpd dd if=/dev/null of=/var/log/$(HTTPD_SERVER)/$(PROJECT)-access.log >/dev/null 2>&1 || true + @#cd $(DEVILBOX_PATH) && docker-compose exec httpd dd if=/dev/null of=/var/log/$(HTTPD_SERVER)/$(PROJECT)-error.log >/dev/null 2>&1 || true + @#cd $(DEVILBOX_PATH) && docker-compose exec httpd dd if=/dev/null of=/var/log/$(HTTPD_SERVER)/$(PROJECT)_ssl-access.log >/dev/null 2>&1 || true + @#cd $(DEVILBOX_PATH) && docker-compose exec httpd dd if=/dev/null of=/var/log/$(HTTPD_SERVER)/$(PROJECT)_ssl-error.log >/dev/null 2>&1 || true + + +_logs: + @echo "####################################################################################################" + @echo "# SHOWING LOGS" + @echo "####################################################################################################" + @echo + + $(eval HTTPD_SERVER := $(shell grep -E '^HTTPD_SERVER' $(DEVILBOX_PATH)/.env | sed 's/.*=//g')) + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [DOCKER] docker-compose ps" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose ps; + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [DOCKER] [HTTPD] docker-compose logs httpd" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose logs httpd; + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [DOCKER] [PHP] docker-compose logs php" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose logs php; + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [DOCKER] [BIND] docker-compose logs bind" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose logs bind; + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [DOCKER] [MYSQL] docker-compose logs mysql" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose logs mysql; + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [DOCKER] [PGSQL] docker-compose logs pgsql" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose logs pgsql; + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [DOCKER] [REDIS] docker-compose logs redis" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose logs redis; + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [DOCKER] [MEMCD] docker-compose logs memcd" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose logs memcd; + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [DOCKER] [MONGO] docker-compose logs mongo" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose logs mongo; + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [PHP] php-fpm.access" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose exec php cat /var/log/php/php-fpm.access || true + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [PHP] php-fpm.error" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose exec php cat /var/log/php/php-fpm.error || true + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [HTTPD] defaultlocalhost-access.log" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose exec httpd cat /var/log/$(HTTPD_SERVER)/defaultlocalhost-access.log || true + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [HTTPD] defaultlocalhost-error.log" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose exec httpd cat /var/log/$(HTTPD_SERVER)/defaultlocalhost-error.log || true + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [HTTPD] defaultlocalhost_ssl-access.log" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose exec httpd cat /var/log/$(HTTPD_SERVER)/defaultlocalhost_ssl-access.log || true + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [HTTPD] defaultlocalhost_ssl-error.log" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose exec httpd cat /var/log/$(HTTPD_SERVER)/defaultlocalhost_ssl-error.log || true + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [HTTPD] $(PROJECT)-access.log" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose exec httpd cat /var/log/$(HTTPD_SERVER)/$(PROJECT)-access.log || true + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [HTTPD] $(PROJECT)-error.log" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose exec httpd cat /var/log/$(HTTPD_SERVER)/$(PROJECT)-error.log || true + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [HTTPD] $(PROJECT)_ssl-access.log" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose exec httpd cat /var/log/$(HTTPD_SERVER)/$(PROJECT)_ssl-access.log || true + @echo + + @echo "# ----------------------------------------------------------------------------------------" + @echo "# [HTTPD] $(PROJECT)_ssl-error.log" + @echo "# ----------------------------------------------------------------------------------------" + cd $(DEVILBOX_PATH) && docker-compose exec httpd cat /var/log/$(HTTPD_SERVER)/$(PROJECT)_ssl-error.log || true + @echo + + +_wait: + @printf "Waiting for container to be ready "; + @# [HTTPD] Test for HTTP Status 200 + @until curl -sS -o /dev/null -I -w "%{http_code}" localhost 2>/dev/null | grep -q '200'; do \ + printf "."; \ + sleep 1; \ + done; + + @# [PHP] Test for HTTP content + @until curl -sS localhost 2>/dev/null | grep -q 'dvlbox-ok'; do \ + printf "."; \ + sleep 1; \ + done; + + @# Add 20 more seconds for other services (e.g.: db) to initialize properly + @for i in $$(seq 1 20); do \ + printf "."; \ + sleep 1; \ + done; + + @# [MongoDB] Test for MongoDB connection + @until cd $(DEVILBOX_PATH) && docker-compose exec php mongofiles --host=mongo list >/dev/null 2>&2; do \ + printf "."; \ + sleep 1; \ + done; + + @# [MYSQL] Test for MySQL connection + @until cd $(DEVILBOX_PATH) && docker-compose exec php mysql --user=root --password='' --host=mysql -e 'show databases;' 2>&1 | grep -q mysql; do \ + printf "."; \ + sleep 1; \ + done; + + @# [PGSQL] Test for PGSQL connection + @until cd $(DEVILBOX_PATH) && docker-compose exec php pg_isready --host=pgsql >/dev/null 2>&1; do \ + printf "."; \ + sleep 1; \ + done; + + @# Add 40 more seconds just to be sure + @for i in $$(seq 1 40); do \ + printf "."; \ + sleep 1; \ + done; + @printf "\n"; diff --git a/.tests/README.md b/.tests/README.md new file mode 100644 index 00000000..9a8a88fe --- /dev/null +++ b/.tests/README.md @@ -0,0 +1,47 @@ +# Devilbox tests + +**Important:** Do not run this locally. + +The Makefile will +* overwrite your `.env` file. +* empty your local Devilbox emails +* empty your local Devilbox logs + + +## Test workflow + +If you nevertheless want to run the tests locally, follow the instructions below in that order. + +#### Initialization +```bash +# Overwrites .env with testing defaults +make init +``` + +#### Configure +```bash +# Configure custom versions (optionally) +make configure SRV=PHP_SERVER VER=5.6 +make configure SRV=HTTPD_SERVER VER=apache-2.2 +``` + +#### Start +```bash +make start +``` + +#### Info +```bash +make info +``` + +#### Test + +```bash +make test +``` + +#### Stop +```bash +make stop +``` diff --git a/.tests/intra-tests/README.md b/.tests/intra-tests/README.md new file mode 100644 index 00000000..41056955 --- /dev/null +++ b/.tests/intra-tests/README.md @@ -0,0 +1,4 @@ +# Intranet tests + +This directory includes scripts that run tests against the Devilbox intranet. +Each file must be executable and end by `*.sh`. diff --git a/.tests/intra-tests/homepage.sh b/.tests/intra-tests/homepage.sh new file mode 100755 index 00000000..0b1bf733 --- /dev/null +++ b/.tests/intra-tests/homepage.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + +NUM_OK="20" +NUM_ERR="0" + + +### +### dvlbox-ok +### + +printf "[TEST] dvlbox-ok" +# 1st Try +TEST_OK="$( curl -sS localhost/index.php | grep -c 'dvlbox-ok' || true )" +if [ "${TEST_OK}" != "${NUM_OK}" ]; then + # 2nd Try + TEST_OK="$( curl -sS localhost/index.php | grep -c 'dvlbox-ok' || true )" + if [ "${TEST_OK}" != "${NUM_OK}" ]; then + # 3rd Try + TEST_OK="$( curl -sS localhost/index.php | grep -c 'dvlbox-ok' || true )" + if [ "${TEST_OK}" != "${NUM_OK}" ]; then + printf "\r[FAIL] dvlbox-ok\n" + curl -sS localhost/index.php | grep -c 'dvlbox-ok' || true + exit 1 + else + printf "\r[OK] dvlbox-ok (3 rounds)\n" + fi + else + printf "\r[OK] dvlbox-ok (2 rounds)\n" + fi +else + printf "\r[OK] dvlbox-ok (1 round)\n" +fi + + +### +### dvlbox-err +### + +printf "[TEST] dvlbox-err" +# 1st Try +TEST_ERR="$( curl -sS localhost/index.php | grep -c 'dvlbox-err' || true )" +if [ "${TEST_ERR}" != "${NUM_ERR}" ]; then + # 2nd Try + TEST_ERR="$( curl -sS localhost/index.php | grep -c 'dvlbox-err' || true )" + if [ "${TEST_ERR}" != "${NUM_ERR}" ]; then + # 3rd Try + TEST_ERR="$( curl -sS localhost/index.php | grep -c 'dvlbox-err' || true )" + if [ "${TEST_ERR}" != "${NUM_ERR}" ]; then + printf "\r[FAIL] dvlbox-err\n" + curl -sS localhost/index.php | grep -c 'dvlbox-err' || true + exit 1 + else + printf "\r[OK] dvlbox-err (3 rounds)\n" + fi + else + printf "\r[OK] dvlbox-err (2 rounds)\n" + fi +else + printf "\r[OK] dvlbox-err (1 round)\n" +fi diff --git a/.tests/test_single.sh b/.tests/test_single.sh deleted file mode 100755 index 05c43f31..00000000 --- a/.tests/test_single.sh +++ /dev/null @@ -1,147 +0,0 @@ -#!/bin/sh -eu - -################################################################################ -# -# Arguments -# -################################################################################ - -### -### Validate arguments -### -if [ "${#}" != "5" ]; then - echo "Error: Invalid number of arguments" - exit 1 -fi - -if [ ! -d "${1}" ]; then - echo "Error: Not a directory: ${1}" - exit 1 -fi - -### -### Get arguments -### -DVL_PATH="$( echo "${1}"| sed 's/\/*$//' )" # remove last slash(es): / -DVL_SRV1="${2}" # Server 1 -DVL_VER1="${3}" # Version 1 -DVL_SRV2="${4}" # Server 2 -DVL_VER2="${5}" # Version 2 - - - -################################################################################ -# -# Bootstrap -# -################################################################################ - -### -### Source library -### -. "${DVL_PATH}/.tests/.lib.sh" "${DVL_PATH}" - -### -### Reset .env file -### -reset_env_file - -### -### Enable debug mode -### -set_debug_enable - -### -### Alter host ports -### -set_host_port_httpd "80" -set_host_port_mysql "3306" -set_host_port_pgsql "5432" - -### -### Default values for container -### -DEF_PHP="7.0" -DEF_HTTPD="nginx-stable" -DEF_MYSQL="mariadb-10.0" -DEF_PGSQL="9.6" - - - -################################################################################ -# -# Test -# -################################################################################ - -### -### Docker Host settings -### -print_h1 "Docker Host settings" - -print_h2 "Listening services" -run "netstat -tulpn" - -print_h2 "Docker version" -run "docker --version" -run "docker-compose --version" - - - -### -### Configure -### -print_h1 "Configuration: ${DVL_SRV1}-${DVL_VER1} vs ${DVL_SRV2}-${DVL_VER2}" - -print_h2 "Enabled settings in .env" -devilbox_configure "${DVL_SRV1}" "${DVL_VER1}" "${DVL_SRV2}" "${DVL_VER2}" "${DEF_PHP}" "${DEF_HTTPD}" "${DEF_MYSQL}" "${DEF_PGSQL}" -devilbox_configured_settings - - - -### -### Download and run -### -print_h1 "Startup Devilbox" - -print_h2 "Download" -devilbox_pull - -print_h2 "Run" -devilbox_start - -print_h2 "Actual settings from index.php" -devilbox_print_actual_settings - - - -### -### Test -### -print_h1 "Testing" - -print_h2 "docker-compose" -if ! devilbox_test_compose; then - devilbox_print_errors "http://127.0.0.1/index.php" - exit 1 -fi - -print_h2 "Testing 'dvlbox-ok': index.php" -if ! devilbox_test_url "http://127.0.0.1/index.php" "dvlbox-ok" "20"; then - devilbox_print_errors "http://127.0.0.1/index.php" - exit 1 -fi - -print_h2 "Testing 'dvlbox-err': index.php" -if ! devilbox_test_url "http://127.0.0.1/index.php" "dvlbox-err" "0"; then - devilbox_print_errors "http://127.0.0.1/index.php" - exit 1 -fi - - - -### -### Stop -### -print_h1 "Shutdown and exit" -devilbox_stop diff --git a/.tests/vhost-tests/README.md b/.tests/vhost-tests/README.md new file mode 100644 index 00000000..c6f636e3 --- /dev/null +++ b/.tests/vhost-tests/README.md @@ -0,0 +1,7 @@ +# Virtual host tests + +Tests in this directory are run by a virtual host as well as executed on the cli inside the +PHP container. + +Every single PHP file must echo out `OK` and only `OK` if it succeeded. +The tests are looking for the following regex string in the complete output: `/^OK$/`. diff --git a/.tests/vhost-tests/htdocs/intranet-mail.php b/.tests/vhost-tests/htdocs/intranet-mail.php new file mode 100644 index 00000000..ae01eb2c --- /dev/null +++ b/.tests/vhost-tests/htdocs/intranet-mail.php @@ -0,0 +1,46 @@ +getServerList(); + +if (empty($list)) { + $memcd->setOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE, true); + $memcd->setOption(\Memcached::OPT_BINARY_PROTOCOL, false); + $memcd->addServer($MY_HOST, $MY_PORT); +} + +$stats = $memcd->getStats(); + +if (!isset($stats[$MY_HOST.':'.$MY_PORT])) { + $memcd->quit(); + echo "FAIL - Failed to connect to Memcached host on '.$MYHOST' (no connection array)"; + exit(1); +} + +if (!isset($stats[$MY_HOST.':'.$MY_PORT]['pid'])) { + $memcd->quit(); + echo "FAIL - Failed to connect to Memcached host on '.$MYHOST' (no pid)"; + exit(1); +} +if ($stats[$MY_HOST.':'.$MY_PORT]['pid'] < 1) { + $memcd->quit(); + echo "FAIL - Failed to connect to Memcached host on '.$MYHOST' (invalid pid)"; + exit(1); +} + +if (! $memcd->add($MY_KEY, $MY_VAL)) { + $memcd->quit(); + echo "FAIL - Failed to add key"; + exit(1); +} + +if ($memcd->get($MY_KEY) != $MY_VAL) { + $memcd->quit(); + echo "FAIL - Added and retrieved key do not match."; + exit(1); +} +$memcd->delete($MY_KEY); +$memcd->quit(); +echo "OK"; diff --git a/.tests/vhost-tests/htdocs/mongodb.php b/.tests/vhost-tests/htdocs/mongodb.php new file mode 100644 index 00000000..5f5ca121 --- /dev/null +++ b/.tests/vhost-tests/htdocs/mongodb.php @@ -0,0 +1,39 @@ + 1)); + +try { + $mongo->executeCommand('admin', $command); +} catch (\MongoDB\Driver\Exception\ConnectionTimeoutException $e) { + echo 'FAIL - ' . $e; + exit(1); +} + +// retrieve server list +$servers = $mongo->getServers(); + +if (!isset($servers[0])) { + echo 'FAIL - Failed to connect to MongoDB host on '.$MY_HOST.' (No host info available)'; + exit(1); +} +if ($servers[0]->getHost() != $MY_HOST) { + echo 'FAIL - Failed to connect to MongoDB host on '.$MY_HOST.' (servername does not match: '.$servers[0]->getHost().')'; + exit(1); +} + +echo 'OK'; diff --git a/.tests/vhost-tests/htdocs/mysql.php b/.tests/vhost-tests/htdocs/mysql.php new file mode 100644 index 00000000..e8f699ed --- /dev/null +++ b/.tests/vhost-tests/htdocs/mysql.php @@ -0,0 +1,44 @@ +fetch_array(MYSQLI_ASSOC)) { + $data[] = $row; +} +mysqli_free_result($result); +mysqli_close($link); + +if (!isset($data[0])) { + echo 'FAIL'; + exit(1); +} +if ($data[0]['User'] == 'root') { + echo 'OK'; + exit(0); +} else { + echo 'FAIL'; + exit(1); +} diff --git a/.tests/vhost-tests/htdocs/postgres.php b/.tests/vhost-tests/htdocs/postgres.php new file mode 100644 index 00000000..98412e76 --- /dev/null +++ b/.tests/vhost-tests/htdocs/postgres.php @@ -0,0 +1,40 @@ + 0) { + echo 'OK'; + exit(0); +} else { + echo 'FAIL'; + exit(1); +} diff --git a/.tests/vhost-tests/htdocs/redis.php b/.tests/vhost-tests/htdocs/redis.php new file mode 100644 index 00000000..a157a194 --- /dev/null +++ b/.tests/vhost-tests/htdocs/redis.php @@ -0,0 +1,40 @@ +connect($MY_HOST, $MY_PORT, 0.5, NULL)) { + echo 'FAIL'; + exit(1); +} else { + $redis->set($MY_KEY, $MY_VAL); +} + +foreach ($redis->info('all') as $key => $val) { + if (preg_match('/db[0-9]+/', $key)) { + $database = str_replace('db', '', $key); + $redis->select($database); + if ($redis->get($MY_KEY) == $MY_VAL) { + echo 'OK'; + $redis->close(); + exit(1); + } + } +} + +$redis->close(); +echo 'FAIL'; +exit(1); diff --git a/.travis.yml b/.travis.yml index 760ed444..8434a6f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,35 +40,35 @@ env: ### Compose versions: https://github.com/docker/compose/releases ### # Latest Docker version against various DockerCompose versions + - S1=DOCKER V1=1 S2=COMPOSE V2=1 + - S1=DOCKER V1=1 S2=COMPOSE V2=2 + - S1=DOCKER V1=1 S2=COMPOSE V2=3 + - S1=DOCKER V1=1 S2=COMPOSE V2=4 + - S1=DOCKER V1=1 S2=COMPOSE V2=5 + # 2nd Latest Docker version against various DockerCompose versions - S1=DOCKER V1=2 S2=COMPOSE V2=1 - S1=DOCKER V1=2 S2=COMPOSE V2=2 - S1=DOCKER V1=2 S2=COMPOSE V2=3 - S1=DOCKER V1=2 S2=COMPOSE V2=4 - S1=DOCKER V1=2 S2=COMPOSE V2=5 - # 2nd Latest Docker version against various DockerCompose versions + # 3rd Latest Docker version against various DockerCompose versions - S1=DOCKER V1=3 S2=COMPOSE V2=1 - S1=DOCKER V1=3 S2=COMPOSE V2=2 - S1=DOCKER V1=3 S2=COMPOSE V2=3 - S1=DOCKER V1=3 S2=COMPOSE V2=4 - S1=DOCKER V1=3 S2=COMPOSE V2=5 - # 3rd Latest Docker version against various DockerCompose versions + # 4th Latest Docker version against various DockerCompose versions - S1=DOCKER V1=4 S2=COMPOSE V2=1 - S1=DOCKER V1=4 S2=COMPOSE V2=2 - S1=DOCKER V1=4 S2=COMPOSE V2=3 - S1=DOCKER V1=4 S2=COMPOSE V2=4 - S1=DOCKER V1=4 S2=COMPOSE V2=5 - # 4th Latest Docker version against various DockerCompose versions + # 5th Latest Docker version against various DockerCompose versions - S1=DOCKER V1=5 S2=COMPOSE V2=1 - S1=DOCKER V1=5 S2=COMPOSE V2=2 - S1=DOCKER V1=5 S2=COMPOSE V2=3 - S1=DOCKER V1=5 S2=COMPOSE V2=4 - S1=DOCKER V1=5 S2=COMPOSE V2=5 - # 5th Latest Docker version against various DockerCompose versions - - S1=DOCKER V1=6 S2=COMPOSE V2=1 - - S1=DOCKER V1=6 S2=COMPOSE V2=2 - - S1=DOCKER V1=6 S2=COMPOSE V2=3 - - S1=DOCKER V1=6 S2=COMPOSE V2=4 - - S1=DOCKER V1=6 S2=COMPOSE V2=5 ### ### The matrix specifies 2 versions to compare against each other. @@ -132,17 +132,17 @@ install: max=100; i=0; while [ $i -lt $max ]; do if pip install sphinx_rtd_theme; then break; else i=$((i+1)); fi done; fi - # Determine latest Docker version + # Determine latest Docker version in apt - set -e; DOCKER_APT=""; if [ "${S1}" = "DOCKER" ]; then - DOCKER_VERSION="$( curl -sS https://raw.githubusercontent.com/cytopia/tools/master/docker-versions | sh -s "${V1}" | grep -oE '[.0-9]+' )"; - DOCKER_APT="$( apt-cache madison docker-ce | grep "${DOCKER_VERSION}" | awk -F '|' '{ print $2}' | head -1 | xargs )"; + max=100; i=0; while [ $i -lt $max ]; do if sudo apt-get update -qq; then break; else i=$((i+1)); fi; done; + DOCKER_APT="$( curl -sS https://raw.githubusercontent.com/cytopia/tools/master/docker-apt-versions | sh -s "${V1}" )"; fi; if [ -n "${DOCKER_APT}" ]; then DOCKER_APT="=${DOCKER_APT}"; fi; - echo "${COMPOSE_APT}"; + echo "${DOCKER_APT}"; # Determine latest Docker Compose version - set -e; @@ -213,8 +213,17 @@ script: elif [ "${S1}" = "UPDATE" ]; then ./update-docker.sh "${V1}"; elif [ "${S1}" = "DOCKER" ]; then - PHP="$(grep ^PHP_SERVER env-example | grep -Eo '[.0-9]+')"; - .tests/test_single.sh . "PHP" "${PHP}" "PHP" "${PHP}"; + cd .tests/; + make init; + make start; + make info; + make test; else - .tests/test_single.sh . "${S1}" "${V1}" "${S2}" "${V2}"; + cd .tests/; + make init; + make configure SRV="${S1}_SERVER" VER="${V1}"; + make configure SRV="${S2}_SERVER" VER="${V2}"; + make start; + make info; + make test; fi