Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Testsuite for Joomla #14630

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ imageTests+=(
julia-hello-world
julia-downloads
'
[joomla]='
joomla-cli-mariadb
'
[joomla:apache]='
joomla-apache-run
'
[joomla:fpm]='
joomla-fpm-run
'
[logstash]='
logstash-basics
'
Expand Down
57 changes: 57 additions & 0 deletions test/tests/joomla-apache-run/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
set -Eeo pipefail

dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"

dbImage='mariadb:10.11'
# ensure the dbImage is ready and available
if ! docker image inspect "$dbImage" &> /dev/null; then
docker pull "$dbImage" > /dev/null
fi
serverImage="$1"
dbPass="test-$RANDOM-password-$RANDOM-$$"
dbName="test-$RANDOM-db"
dbUsr="test-$RANDOM-db"

# Use a client image with curl for testing
clientImage='buildpack-deps:buster-curl'
# ensure the clientImage is ready and available
if ! docker image inspect "$clientImage" &> /dev/null; then
docker pull "$clientImage" > /dev/null
fi

# Create an instance of the container-under-test
dbCid="$(docker run -d \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_USER="$dbUsr" \
-e MYSQL_PASSWORD="$dbPass" \
-e MYSQL_DATABASE="$dbName" \
"$dbImage")"
trap "docker rm -vf $dbCid > /dev/null" EXIT
cid="$(docker run -d \
--link "$dbCid":db \
-e JOOMLA_DB_HOST="db:3306" \
-e JOOMLA_DB_NAME="$dbName" \
-e JOOMLA_DB_USER="$dbUsr" \
-e JOOMLA_DB_PASSWORD="$dbPass" \
"$serverImage")"
trap "docker rm -vf $cid $dbCid > /dev/null" EXIT

_request() {
local method="$1"
shift

local url="${1#/}"
shift

docker run --rm \
--link "$cid":apache \
"$clientImage" \
curl -fsL -X"$method" "$@" "http://apache/$url"
}

# Make sure that Apache is listening and ready
. "$dir/../../retry.sh" --tries 5 --sleep 10 '_request GET / --output /dev/null'

# Check that we can request / and that it contains the pattern 'Joomla Installer' somewhere
_request GET '/' | grep -i 'Joomla Installer'
52 changes: 52 additions & 0 deletions test/tests/joomla-cli-mariadb/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
set -Eeo pipefail

dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"

dbImage='mariadb:10.11'
# ensure the dbImage is ready and available
if ! docker image inspect "$dbImage" &> /dev/null; then
docker pull "$dbImage" > /dev/null
fi
serverImage="$1"
dbPass="test-$RANDOM-password-$RANDOM-$$"
dbName="test-$RANDOM-db"
dbUsr="test-$RANDOM-db"

# Create an instance of the container-under-test
dbCid="$(docker run -d \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_USER="$dbUsr" \
-e MYSQL_PASSWORD="$dbPass" \
-e MYSQL_DATABASE="$dbName" \
"$dbImage")"
trap "docker rm -vf $dbCid > /dev/null" EXIT
cid="$(docker run -d \
--link "$dbCid":db \
-e JOOMLA_DB_HOST="db:3306" \
-e JOOMLA_DB_NAME="$dbName" \
-e JOOMLA_DB_USER="$dbUsr" \
-e JOOMLA_DB_PASSWORD="$dbPass" \
"$serverImage")"
trap "docker rm -vf $cid $dbCid > /dev/null" EXIT

_cli() {
docker exec -u www-data "$cid" php installation/joomla.php install -n \
--site-name="test-$RANDOM" \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically I advise against using random variables in unit tests - you want them to be perfectly replicable on each run

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In these tests, we encourage random variance because it usually increases the chances that the test is actually testing something meaningful instead of just hitting the happy path every time (for example, putting a "default" value in the test that just happens to work because it matches the default of the image when the image wouldn't handle a non-default value, for example).

--admin-user="test-$RANDOM" \
--admin-username="test-$RANDOM" \
--admin-password="test-$RANDOM-password" \
--admin-email="[email protected]" \
--db-type="mysql" \
--db-host="db" \
--db-user="$dbUsr" \
--db-pass="$dbPass" \
--db-name="$dbName"
}

# Give some time to install
. "$dir/../../retry.sh" --tries 20 --sleep 5 'docker exec "$cid" ls installation/joomla.php'

# Check if Joomla is installed
_cli
docker exec -u www-data "$cid" php cli/joomla.php list | grep -i 'Joomla!'
67 changes: 67 additions & 0 deletions test/tests/joomla-fpm-run/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash
set -Eeo pipefail

dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"

dbImage='mariadb:10.11'
# ensure the dbImage is ready and available
if ! docker image inspect "$dbImage" &> /dev/null; then
docker pull "$dbImage" > /dev/null
fi
serverImage="$1"
dbPass="test-$RANDOM-password-$RANDOM-$$"
dbName="test-$RANDOM-db"
dbUsr="test-$RANDOM-db"

# Build a client image with cgi-fcgi for testing
clientImage='librarytest/joomla-fpm-run:fcgi-client'
docker build -t "$clientImage" - > /dev/null <<'EOF'
FROM debian:buster-slim

RUN set -x && apt-get update && apt-get install -y --no-install-recommends libfcgi-bin && rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["cgi-fcgi"]
EOF

# Create an instance of the container-under-test
dbCid="$(docker run -d \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_USER="$dbUsr" \
-e MYSQL_PASSWORD="$dbPass" \
-e MYSQL_DATABASE="$dbName" \
"$dbImage")"
trap "docker rm -vf $dbCid > /dev/null" EXIT
cid="$(docker run -d \
--link "$dbCid":db \
-e JOOMLA_DB_HOST="db:3306" \
-e JOOMLA_DB_NAME="$dbName" \
-e JOOMLA_DB_USER="$dbUsr" \
-e JOOMLA_DB_PASSWORD="$dbPass" \
"$serverImage")"
trap "docker rm -vf $cid $dbCid > /dev/null" EXIT

fcgi-request() {
local method="$1"

local url="$2"
local queryString=
if [[ "$url" == *\?* ]]; then
queryString="${url#*\?}"
url="${url%%\?*}"
fi

docker run --rm -i \
--link "$cid":fpm \
-e REQUEST_METHOD="$method" \
-e SCRIPT_NAME="$url" \
-e SCRIPT_FILENAME=/var/www/html/"${url#/}" \
-e QUERY_STRING="$queryString" \
"$clientImage" \
-bind -connect fpm:9000
}

# Make sure that PHP-FPM is listening and ready
. "$dir/../../retry.sh" --tries 5 --sleep 10 'fcgi-request GET /index.php' > /dev/null 2>&1

# Check that we can request / and that it contains the pattern 'Joomla Installer' somewhere
fcgi-request GET '/installation/index.php' #| grep -qi 'Joomla Installer'