From: gggeek Date: Wed, 16 Dec 2020 23:14:41 +0000 (+0000) Subject: polish test vm X-Git-Tag: plcapi-7.1-0~3^2~110 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=f9b6f0e202eb6fa3f87a6ce309b9091569f43615;p=plcapi.git polish test vm --- diff --git a/.gitignore b/.gitignore index 128cd40..f589b5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ /.idea /build/* -/tests/coverage/* /vendor/* /.phpunit.result.cache /composer.lock diff --git a/.travis.yml b/.travis.yml index 12d85d6..4e66ee5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,8 +65,8 @@ after_failure: # Show as much info as we can to help developers - sudo cat /var/log/privoxy/* - - cat apache_error.log - - cat apache_access.log + - sudo cat /var/log/apache2/error.log + - sudo cat /var/log/apache2/other_vhosts_access.log - sudo cat /var/log/php*.log after_script: diff --git a/README.md b/README.md index 63cece5..5d4261d 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,28 @@ If you are upgrading from version 3 or earlier you have two options: In any case, read carefully the docs in [doc/api_changes_v4.md](doc/api_changes_v4.md) and report back any undocumented issue using GitHub. +Running tests +------------- + +The recommended way to run the library test suite is via the provided Docker containers. +A handy shell script is available that simplifies usage of Docker. + +The full sequence of operations is: + + ./tests/ci/vm.sh build + ./tests/ci/vm.sh start + ./tests/ci/vm.sh runtests + ./tests/ci/vm.sh stop + + # and, once you have finished all testing related work: + ./tests/ci/vm.sh cleanup + +By default tests are run using php 7.0 in a Container based on Ubuntu 16 Xenial. +You can change the version of PHP and Ubuntu in use by setting the environment variables PHP_VERSION and UBUNTU_VERSION +before building the Container. + +To generate the code-coverage report, run `./tests/ci/vm.sh runcoverage` + License ------- Use of this software is subject to the terms in the [license.txt](license.txt) file diff --git a/ChangeLog b/doc/ChangeLog similarity index 99% rename from ChangeLog rename to doc/ChangeLog index e032f79..3db05c3 100644 --- a/ChangeLog +++ b/doc/ChangeLog @@ -1,6 +1,5 @@ -NB: All recent commits are available online. +NB: This is an old changelog. All recent commits are available online at https://github.com/gggeek/phpxmlrpc/commits This file will not be updated further. -See https://github.com/gggeek/phpxmlrpc/commits/master 2014-05-26 - G. Giunta (giunta.gaetano@gmail.com) diff --git a/tests/ci/Dockerfile b/tests/ci/Dockerfile index 7fb27de..15104e6 100644 --- a/tests/ci/Dockerfile +++ b/tests/ci/Dockerfile @@ -23,6 +23,7 @@ RUN chmod 755 /root/entrypoint.sh EXPOSE 80 443 8080 -WORKDIR /home/test +# @todo can we avoid hardcoding this here? We can f.e. get it passed down as ARG... +WORKDIR /home/docker/build ENTRYPOINT ["/root/entrypoint.sh"] diff --git a/tests/ci/config/apache_vhost b/tests/ci/config/apache_vhost index bf7db16..88307bf 100644 --- a/tests/ci/config/apache_vhost +++ b/tests/ci/config/apache_vhost @@ -6,8 +6,8 @@ DocumentRoot ${TESTS_ROOT_DIR} - ErrorLog "${TESTS_ROOT_DIR}/apache_error.log" - CustomLog "${TESTS_ROOT_DIR}/apache_access.log" combined + #ErrorLog "${TESTS_ROOT_DIR}/apache_error.log" + #CustomLog "${TESTS_ROOT_DIR}/apache_access.log" combined # Env vars used by the test code, which we get from the environment SetEnv HTTPSERVER ${HTTPSERVER} @@ -32,8 +32,8 @@ DocumentRoot ${TESTS_ROOT_DIR} - ErrorLog "${TESTS_ROOT_DIR}/apache_error.log" - CustomLog "${TESTS_ROOT_DIR}/apache_access.log" combined + #ErrorLog "${TESTS_ROOT_DIR}/apache_error.log" + #CustomLog "${TESTS_ROOT_DIR}/apache_access.log" combined # Env vars used by the test code, which we get from the environment SetEnv HTTPSERVER ${HTTPSERVER} diff --git a/tests/ci/docker/entrypoint.sh b/tests/ci/docker/entrypoint.sh index 658d8e3..b2c75c3 100644 --- a/tests/ci/docker/entrypoint.sh +++ b/tests/ci/docker/entrypoint.sh @@ -1,8 +1,6 @@ #!/bin/sh -# @todo make username flexible - -USERNAME=test +USERNAME="${1:-docker}" echo "[$(date)] Bootstrapping the Test container..." @@ -41,16 +39,25 @@ if [ $(stat -c '%u' "${CONTAINER_USER_HOME}") != "${CONTAINER_USER_UID}" -o $(st chown "${CONTAINER_USER_UID}":"${CONTAINER_USER_GID}" "${CONTAINER_USER_HOME}" chown -R "${CONTAINER_USER_UID}":"${CONTAINER_USER_GID}" "${CONTAINER_USER_HOME}"/.* fi +# @todo do the same chmod for ${TESTS_ROOT_DIR}, if it's not within CONTAINER_USER_HOME -echo "[$(date)] Fixing apache configuration..." +echo "[$(date)] Fixing Apache configuration..." sed -e "s?^export TESTS_ROOT_DIR=.*?export TESTS_ROOT_DIR=${TESTS_ROOT_DIR}?g" --in-place /etc/apache2/envvars +sed -e "s?^export APACHE_RUN_USER=.*?export APACHE_RUN_USER=${USERNAME}?g" --in-place /etc/apache2/envvars +sed -e "s?^export APACHE_RUN_GROUP=.*?export APACHE_RUN_GROUP=${USERNAME}?g" --in-place /etc/apache2/envvars + +echo "[$(date)] Fixing FPM configuration..." -# @todo set as well php-fpm user/group ? +FPMCONF="/etc/php/$(php -r 'echo implode(".",array_slice(explode(".",PHP_VERSION),0,2));' 2>/dev/null)/fpm/pool.d/www.conf" +sed -e "s?^user =.*?user = ${USERNAME}?g" --in-place "${FPMCONF}" +sed -e "s?^group =.*?group = ${USERNAME}?g" --in-place "${FPMCONF}" +sed -e "s?^listen.owner =.*?listen.owner = ${USERNAME}?g" --in-place "${FPMCONF}" +sed -e "s?^listen.group =.*?listen.group = ${USERNAME}?g" --in-place "${FPMCONF}" echo "[$(date)] Running Composer..." -sudo test -c "cd /home/test && composer install" +sudo "${USERNAME}" -c "cd ${TESTS_ROOT_DIR} && composer install" trap clean_up TERM diff --git a/tests/ci/setup/create_user.sh b/tests/ci/setup/create_user.sh index 4196508..33553d2 100755 --- a/tests/ci/setup/create_user.sh +++ b/tests/ci/setup/create_user.sh @@ -1,11 +1,10 @@ #!/bin/sh -# @todo set up the same user for running tests as on travis (ie. 'travis'), or maybe user 'user' ? # @todo make the GID & UID of the user variable (we picked 2000 as it is the one used by default by Travis) set -e -USERNAME="${1:-test}" +USERNAME="${1:-docker}" addgroup --gid 2000 "${USERNAME}" adduser --system --uid=2000 --gid=2000 --home "/home/${USERNAME}" --shell /bin/bash "${USERNAME}" diff --git a/tests/ci/vm.sh b/tests/ci/vm.sh index 9075c2f..d688514 100755 --- a/tests/ci/vm.sh +++ b/tests/ci/vm.sh @@ -1,6 +1,6 @@ #!/bin/sh -# @todo support getting the 2 vars as cli args as well as via env vars? +# @todo support getting the 2 vars as cli options as well as via env vars? set -e @@ -12,9 +12,11 @@ export PHP_VERSION=${PHP_VERSION:-default} # We default to the same version we use on Travis export UBUNTU_VERSION=${UBUNTU_VERSION:-xenial} +CONTAINER_USER=docker +CONTAINER_BUILD_DIR="/home/${CONTAINER_USER}/build" +ROOT_DIR="$(dirname -- "$(dirname -- "$(dirname -- "$(readlink -f "$0")")")")" IMAGE_NAME=phpxmlrpc:${UBUNTU_VERSION}-${PHP_VERSION} CONTAINER_NAME=phpxmlrpc_${UBUNTU_VERSION}_${PHP_VERSION} -ROOT_DIR="$(dirname -- "$(dirname -- "$(dirname -- "$(readlink -f "$0")")")")" cd "$(dirname -- "$(readlink -f "$0")")" @@ -25,15 +27,23 @@ Manages the Test Environment Docker Stack Commands: build build or rebuild the containers and set up the test env + cleanup removes the docker containers and their images enter enter the test container - #exec \$cmd execute a single shell command in the test container - #runtests [\$suite] execute the test suite using the test container (or a single test scenario eg. Tests/1ParsingBugsTest.php) + inspect + logs + ps + runtests [\$suite] execute the test suite using the test container (or a single test scenario eg. tests/1ParsingBugsTest.php) + runcoverage execute the test suite and generate a code coverage report (in build/coverage) start start the containers - #status stop stop containers + top Options: -h print help + +Environment variables: to be set before the 'build' action + PHP_VERSION default value: 'default', ie. the stock php version from the Ubuntu version in use. Other possible values: 7.0 .. 8.0 + UBUNTU_VERSION default value: xenial. Other possible values: bionic, focal " } @@ -46,7 +56,8 @@ build() { docker run -d \ -p 80:80 -p 443:443 -p 8080:8080 \ --name "${CONTAINER_NAME}" \ - --env CONTAINER_USER_UID=$(id -u) --env CONTAINER_USER_GID=$(id -g) --env TESTS_ROOT_DIR=/home/test \ + --env CONTAINER_USER_UID=$(id -u) --env CONTAINER_USER_GID=$(id -g) \ + --env TESTS_ROOT_DIR=${CONTAINER_BUILD_DIR} \ --env HTTPSERVER=localhost \ --env HTTPURI=/demo/server/server.php \ --env HTTPSSERVER=localhost \ @@ -56,7 +67,8 @@ build() { --env HTTPSIGNOREPEER=1 \ --env SSLVERSION=0 \ --env DEBUG=0 \ - -v "${ROOT_DIR}":/home/test "${IMAGE_NAME}" + -v "${ROOT_DIR}":"${CONTAINER_BUILD_DIR}" \ + "${IMAGE_NAME}" } start() { @@ -86,9 +98,11 @@ case "${ACTION}" in ;; enter | shell | cli) - docker exec -it "${CONTAINER_NAME}" su test + # @todo allow login as root + docker exec -it "${CONTAINER_NAME}" su "${CONTAINER_USER}" ;; + # @todo implement #exec) # ;; @@ -97,8 +111,17 @@ case "${ACTION}" in start ;; - #runtests) - # ;; + runcoverage) + # @todo clean up /tmp/phpxmlrpc and .phpunit.result.cache + if [ ! -d build ]; then mkdir build; fi + docker exec -t "${CONTAINER_NAME}" /home/${CONTAINER_USER}/build/tests/ci/setup/setup_code_coverage.sh enable + docker exec -it "${CONTAINER_NAME}" su "${CONTAINER_USER}" -c "./vendor/bin/phpunit --coverage-html build/coverage -v tests" + docker exec -t "${CONTAINER_NAME}" /home/${CONTAINER_USER}/build/tests/ci/setup/setup_code_coverage.sh disable + ;; + + runtests) + docker exec -it "${CONTAINER_NAME}" su "${CONTAINER_USER}" -c "./vendor/bin/phpunit -v tests" + ;; start) start