From e76d0735d22324f2e235ac0077f0cd2b9559f7e6 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Mon, 13 Nov 2023 16:35:49 +0100 Subject: [PATCH] Add some basic integration checks The idea with these checks is to verify that the basic moodle-docker composition is able to get up and running and that the various entry points (php, web server, mailpit...) are available. This can be expanded in the future to run more checks verifying other services or expectations. Fixes #274 --- .github/workflows/ci.yml | 31 +++++++++++++++++++++ tests/integration-setup.sh | 14 ++++++++++ tests/integration-teardown.sh | 10 +++++++ tests/integration-test.sh | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100755 tests/integration-setup.sh create mode 100755 tests/integration-teardown.sh create mode 100755 tests/integration-test.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4652fa1a9b4..8b9534cd601 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,36 @@ name: moodle-docker CI on: [push, pull_request] jobs: + integration: + name: Integration checks + runs-on: ubuntu-22.04 + + steps: + - name: Checking out moodle-docker + uses: actions/checkout@v3 + + - name: Checking out moodle + uses: actions/checkout@v3 + with: + repository: moodle/moodle + path: moodle + ref: ${{ matrix.branch }} + + - name: Prepare moodle-docker environment + run: | + cp config.docker-template.php moodle/config.php + tests/integration-setup.sh + + - name: Run moodle-docker tests + run: | + tests/integration-test.sh + + - name: Stop moodle-docker + run: | + tests/integration-teardown.sh + PHPUnit: + needs: integration runs-on: ubuntu-22.04 strategy: @@ -94,6 +123,7 @@ jobs: tests/phpunit-teardown.sh Behat: + needs: integration runs-on: ubuntu-22.04 strategy: @@ -185,6 +215,7 @@ jobs: tests/behat-teardown.sh App: + needs: integration runs-on: ubuntu-22.04 strategy: diff --git a/tests/integration-setup.sh b/tests/integration-setup.sh new file mode 100755 index 00000000000..be4612ff2b6 --- /dev/null +++ b/tests/integration-setup.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -e + +basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )" + +export MOODLE_DOCKER_DB=pgsql +export MOODLE_DOCKER_WWWROOT="${basedir}/moodle" + +echo "Pulling docker images" +$basedir/bin/moodle-docker-compose pull +echo "Starting up container" +$basedir/bin/moodle-docker-compose up -d +echo "Waiting for DB to come up" +$basedir/bin/moodle-docker-wait-for-db diff --git a/tests/integration-teardown.sh b/tests/integration-teardown.sh new file mode 100755 index 00000000000..2779e27335f --- /dev/null +++ b/tests/integration-teardown.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -e + +basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )" + +export MOODLE_DOCKER_WWWROOT="${basedir}/moodle" +export MOODLE_DOCKER_DB=pgsql + +echo "Stopping down container" +$basedir/bin/moodle-docker-compose down diff --git a/tests/integration-test.sh b/tests/integration-test.sh new file mode 100755 index 00000000000..51bea108ffe --- /dev/null +++ b/tests/integration-test.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -e + +basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )" + +export MOODLE_DOCKER_WWWROOT="${basedir}/moodle" +export MOODLE_DOCKER_DB=pgsql + +echo "Checking that PHP CLI is available" + +out=$("${basedir}/bin/moodle-docker-compose" exec -T webserver php -r 'echo "Up!";') +if [[ ! "$out" =~ 'Up!' ]]; then + echo "Error: PHP CLI isn't available" + exit 1 +fi + +echo "Checking that the web server is up" + +if ! curl -s -f 'http://localhost:8000' > /dev/null; then + echo "Error: Webserver not available in port 8000" + exit 1 +fi + +echo "Checking that the Moodle site is ready to install" + +out=$(curl -s -L 'http://localhost:8000') +if ! grep -qz 'Installation | Moodle ' <<< "$out"; then + echo "Error: Moodle site not ready to install" + exit 1 +fi + +echo "Checking that mailpit is up" + +if ! curl -s -f -L 'http://localhost:8000/_/mail' > /dev/null; then + echo "Error: Mailpit not available @ http://localhost:8000/_/mail" + exit 1 +fi + +echo "Checking that mailpit is using existing JS and CSS files" + +out=$(curl -s -L 'http://localhost:8000/_/mail') +js=$(grep -oP '(?<=