X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Fci%2Fvm.sh;h=d688514ad8c23696b6c834afd1de89b6d4f9e8b7;hb=f9b6f0e202eb6fa3f87a6ce309b9091569f43615;hp=9075c2ff43a868ec21ff40f24914b4f3b7a42f58;hpb=9354db3aa7572bf371a7ef6dfe37eebc4e8eaf33;p=plcapi.git 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