Commit 5094bb04 authored by Cédric Anne's avatar Cédric Anne
Browse files

Merge branch '9.5/bugfixes'

parents 701e50b3 3d0ce14b
......@@ -10,7 +10,8 @@
"/public/lib/*",
"/public/build/*",
"/tests/config/*",
"/vendor/*"
"/vendor/*",
"**/*.min.js"
],
"env": {
"browser": true,
......
#!/bin/bash -e
# Import variables from .env file if it exists
if [[ -f .env ]]; then
. .env
fi
echo "Init app container home"
mkdir -p $APP_CONTAINER_HOME
......@@ -15,7 +10,7 @@ docker-compose start
if [[ "$UPDATE_FILES_ACL" = true ]]; then
echo "Change files rights to give write access to app container user"
sudo apt-get install acl
sudo apt-get install --assume-yes --no-install-recommends --quiet acl
setfacl --recursive --modify u:1000:rwx $APPLICATION_ROOT
setfacl --recursive --modify u:1000:rwx $APP_CONTAINER_HOME
fi
......
#!/bin/bash -e
ROOT_DIR=$(readlink -f "$(dirname $0)/../..")
echo "Initialize GLPI 0.80 database"
docker-compose exec -T db mysql --user=root --execute="DROP DATABASE IF EXISTS \`glpitest080\`;"
docker-compose exec -T db mysql --user=root --execute="CREATE DATABASE \`glpitest080\`;"
cat $ROOT_DIR/tests/glpi-0.80-empty.sql | docker-compose exec -T db mysql --user=root glpitest080
......@@ -2,11 +2,7 @@
ROOT_DIR=$(readlink -f "$(dirname $0)/../..")
echo "Initialize old versions databases"
docker-compose exec -T db mysql --user=root --execute="DROP DATABASE IF EXISTS \`glpitest080\`;"
docker-compose exec -T db mysql --user=root --execute="CREATE DATABASE \`glpitest080\`;"
cat $ROOT_DIR/tests/glpi-0.80-empty.sql | docker-compose exec -T db mysql --user=root glpitest080
echo "Initialize GLPI 9.5.3 database"
docker-compose exec -T db mysql --user=root --execute="DROP DATABASE IF EXISTS \`glpitest-9.5.3\`;"
docker-compose exec -T db mysql --user=root --execute="CREATE DATABASE \`glpitest-9.5.3\`;"
cat $ROOT_DIR/tests/glpi-9.5.3-empty.sql | docker-compose exec -T db mysql --user=root glpitest-9.5.3
#!/bin/bash -e
ROOT_DIR=$(readlink -f "$(dirname $0)/../..")
echo "Initialize email fixtures"
docker-compose exec -T --user root dovecot doveadm expunge -u glpi mailbox 'INBOX' all
docker-compose exec -T --user root dovecot doveadm purge -u glpi
for f in `ls $ROOT_DIR/tests/emails-tests/*.eml`; do
cat $f | docker-compose exec -T --user glpi dovecot getmail_maildir /home/glpi/Maildir/
done
......@@ -12,10 +12,3 @@ done
for f in `ls $ROOT_DIR/tests/LDAP/ldif/*.ldif`; do
cat $f | docker-compose exec -T openldap ldapadd -x -H ldap://127.0.0.1:3890/ -D "cn=Manager,dc=glpi,dc=org" -w insecure
done
echo "Initialize email fixtures"
docker-compose exec -T --user root dovecot doveadm expunge -u glpi mailbox 'INBOX' all
docker-compose exec -T --user root dovecot doveadm purge -u glpi
for f in `ls $ROOT_DIR/tests/emails-tests/*.eml`; do
cat $f | docker-compose exec -T --user glpi dovecot getmail_maildir /home/glpi/Maildir/
done
#!/bin/bash -e
ROOT_DIR=$(readlink -f "$(dirname $0)/../..")
echo $ROOT_DIR
echo "Check for syntax errors"
vendor/bin/parallel-lint \
......
#!/bin/bash -e
LOG_FILE="./tests/files/_log/install.log"
mkdir -p $(dirname "$LOG_FILE")
# Execute install
bin/console glpi:database:install \
--config-dir=./tests --ansi --no-interaction \
--config-dir=./tests/config --ansi --no-interaction \
--force \
--reconfigure --db-name=glpi --db-host=db --db-user=root \
--log-deprecation-warnings \
| tee install.log
if [[ -n $(grep "Warning" install.log) ]];
| tee $LOG_FILE
if [[ -n $(grep "Warning" $LOG_FILE) ]];
then echo "glpi:database:install command FAILED" && exit 1;
fi
# Check DB
bin/console glpi:database:check_schema --config-dir=./tests --ansi --no-interaction --strict
bin/console glpi:database:check_keys --config-dir=./tests --ansi --no-interaction --detect-useless-keys
bin/console glpi:database:check_schema --config-dir=./tests/config --ansi --no-interaction --strict
bin/console glpi:database:check_keys --config-dir=./tests/config --ansi --no-interaction --detect-useless-keys
# Execute update
## Should do nothing.
bin/console glpi:database:update --config-dir=./tests --ansi --no-interaction | tee migration.log
if [[ -z $(grep "No migration needed." migration.log) ]];
bin/console glpi:database:update --config-dir=./tests/config --ansi --no-interaction | tee $LOG_FILE
if [[ -z $(grep "No migration needed." $LOG_FILE) ]];
then echo "glpi:database:update command FAILED" && exit 1;
fi
......@@ -5,7 +5,7 @@ TMP_CACHE_DIR=$(mktemp -d -t glpi-cache-test-XXXXXXXXXX)
for CONFIG in {"--use-default","--dsn=memcached://memcached","--dsn=redis://redis"}; do
echo "Test cache using following config: $CONFIG"
php bin/console cache:configure \
--config-dir=./tests --ansi --no-interaction \
--config-dir=./tests/config --ansi --no-interaction \
$CONFIG
vendor/bin/atoum \
-p 'php -d memory_limit=512M' \
......
#!/bin/bash -e
LOG_FILE="./tests/files/_log/migration.log"
mkdir -p $(dirname "$LOG_FILE")
bin/console glpi:database:configure \
--config-dir=./tests --no-interaction --ansi \
--config-dir=./tests/config --no-interaction --ansi \
--reconfigure --db-name=glpitest-9.5.3 --db-host=db --db-user=root --use-utf8mb4 \
--log-deprecation-warnings
# Force ROW_FORMAT=DYNAMIC to prevent tests MySQL 5.6 and MariaDB 10.1 databases
# failure on indexes creation for varchar(255) fields.
## Result will depend on DB server/version, we just expect that command will not fail.
bin/console glpi:migration:dynamic_row_format --config-dir=./tests --ansi --no-interaction
bin/console glpi:migration:dynamic_row_format --config-dir=./tests/config --ansi --no-interaction
# Execute update
## First run should do the migration (with no warnings).
## TODO Remove the --force option when schema version will be updated in define.php
bin/console glpi:database:update --config-dir=./tests --ansi --no-interaction --allow-unstable --force | tee ~/migration.log
if [[ -n $(grep "Warning\|No migration needed." ~/migration.log) ]];
bin/console glpi:database:update --config-dir=./tests/config --ansi --no-interaction --allow-unstable --force | tee $LOG_FILE
if [[ -n $(grep "Warning\|No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:database:update command FAILED" && exit 1;
fi
## Second run should do nothing.
bin/console glpi:database:update --config-dir=./tests --ansi --no-interaction --allow-unstable | tee ~/migration.log
if [[ -z $(grep "No migration needed." ~/migration.log) ]];
bin/console glpi:database:update --config-dir=./tests/config --ansi --no-interaction --allow-unstable | tee $LOG_FILE
if [[ -z $(grep "No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:database:update command FAILED" && exit 1;
fi
## Check DB
bin/console glpi:database:check_schema --config-dir=./tests --ansi --no-interaction --ignore-utf8mb4-migration
bin/console glpi:database:check_schema --config-dir=./tests/config --ansi --no-interaction --ignore-utf8mb4-migration
# Execute myisam_to_innodb migration
## First run should do nothing.
bin/console glpi:migration:myisam_to_innodb --config-dir=./tests --ansi --no-interaction | tee ~/migration.log
if [[ -z $(grep "No migration needed." ~/migration.log) ]];
bin/console glpi:migration:myisam_to_innodb --config-dir=./tests/config --ansi --no-interaction | tee $LOG_FILE
if [[ -z $(grep "No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:migration:myisam_to_innodb command FAILED" && exit 1;
fi
# Execute timestamps migration
## First run should do nothing.
bin/console glpi:migration:timestamps --config-dir=./tests --ansi --no-interaction | tee ~/migration.log
if [[ -z $(grep "No migration needed." ~/migration.log) ]];
bin/console glpi:migration:timestamps --config-dir=./tests/config --ansi --no-interaction | tee $LOG_FILE
if [[ -z $(grep "No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:migration:timestamps command FAILED" && exit 1;
fi
# Execute utf8mb4 migration
## First run should do the migration (with no warnings).
bin/console glpi:migration:utf8mb4 --config-dir=./tests --ansi --no-interaction | tee ~/migration.log
if [[ -n $(grep "Warning\|No migration needed." ~/migration.log) ]];
bin/console glpi:migration:utf8mb4 --config-dir=./tests/config --ansi --no-interaction | tee $LOG_FILE
if [[ -n $(grep "Warning\|No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:migration:utf8mb4 command FAILED" && exit 1;
fi
## Second run should do nothing.
bin/console glpi:migration:utf8mb4 --config-dir=./tests --ansi --no-interaction | tee ~/migration.log
if [[ -z $(grep "No migration needed." ~/migration.log) ]];
bin/console glpi:migration:utf8mb4 --config-dir=./tests/config --ansi --no-interaction | tee $LOG_FILE
if [[ -z $(grep "No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:migration:utf8mb4 command FAILED" && exit 1;
fi
# Check DB
bin/console glpi:database:check_schema --config-dir=./tests --ansi --no-interaction
bin/console glpi:database:check_schema --config-dir=./tests/config --ansi --no-interaction
# Check updated data
bin/console glpi:database:configure \
--config-dir=./tests --no-interaction --ansi \
--config-dir=./tests/config --no-interaction --ansi \
--reconfigure --db-name=glpi --db-host=db --db-user=root --use-utf8mb4 \
--log-deprecation-warnings
mkdir -p ./tests/files/_cache
......
#!/bin/bash -e
LOG_FILE="./tests/files/_log/migration.log"
mkdir -p $(dirname "$LOG_FILE")
# Reconfigure DB
bin/console glpi:database:configure \
--config-dir=./tests --ansi --no-interaction \
--config-dir=./tests/config --ansi --no-interaction \
--reconfigure --db-name=glpitest080 --db-host=db --db-user=root
# Execute update
## First run should do the migration (with no warnings).
bin/console glpi:database:update --config-dir=./tests --ansi --no-interaction --allow-unstable | tee ~/migration.log
if [[ -n $(grep "Warning\|No migration needed." ~/migration.log) ]];
bin/console glpi:database:update --config-dir=./tests/config --ansi --no-interaction --allow-unstable | tee $LOG_FILE
if [[ -n $(grep "Warning\|No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:database:update command FAILED" && exit 1;
fi
## Second run should do nothing.
bin/console glpi:database:update --config-dir=./tests --ansi --no-interaction --allow-unstable | tee ~/migration.log
if [[ -z $(grep "No migration needed." ~/migration.log) ]];
bin/console glpi:database:update --config-dir=./tests/config --ansi --no-interaction --allow-unstable | tee $LOG_FILE
if [[ -z $(grep "No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:database:update command FAILED" && exit 1;
fi
## Check DB
bin/console glpi:database:check_schema \
--config-dir=./tests --ansi --no-interaction \
--config-dir=./tests/config --ansi --no-interaction \
--ignore-innodb-migration --ignore-timestamps-migration --ignore-dynamic-row-format-migration --ignore-utf8mb4-migration
# Execute myisam_to_innodb migration
## First run should do the migration (with no warnings).
bin/console glpi:migration:myisam_to_innodb --config-dir=./tests --ansi --no-interaction | tee ~/migration.log
if [[ -n $(grep "Warning\|No migration needed." ~/migration.log) ]];
bin/console glpi:migration:myisam_to_innodb --config-dir=./tests/config --ansi --no-interaction | tee $LOG_FILE
if [[ -n $(grep "Warning\|No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:migration:myisam_to_innodb command FAILED" && exit 1;
fi
## Second run should do nothing.
bin/console glpi:migration:myisam_to_innodb --config-dir=./tests --ansi --no-interaction | tee ~/migration.log
if [[ -z $(grep "No migration needed." ~/migration.log) ]];
bin/console glpi:migration:myisam_to_innodb --config-dir=./tests/config --ansi --no-interaction | tee $LOG_FILE
if [[ -z $(grep "No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:migration:myisam_to_innodb command FAILED" && exit 1;
fi
## Check DB
bin/console glpi:database:check_schema \
--config-dir=./tests --ansi --no-interaction \
--config-dir=./tests/config --ansi --no-interaction \
--ignore-timestamps-migration --ignore-dynamic-row-format-migration --ignore-utf8mb4-migration
# Execute timestamps migration
## First run should do the migration (with no warnings).
bin/console glpi:migration:timestamps --config-dir=./tests --ansi --no-interaction | tee ~/migration.log
if [[ -n $(grep "Warning\|No migration needed." ~/migration.log) ]];
bin/console glpi:migration:timestamps --config-dir=./tests/config --ansi --no-interaction | tee $LOG_FILE
if [[ -n $(grep "Warning\|No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:migration:timestamps command FAILED" && exit 1;
fi
## Second run should do nothing.
bin/console glpi:migration:timestamps --config-dir=./tests --ansi --no-interaction | tee ~/migration.log
if [[ -z $(grep "No migration needed." ~/migration.log) ]];
bin/console glpi:migration:timestamps --config-dir=./tests/config --ansi --no-interaction | tee $LOG_FILE
if [[ -z $(grep "No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:migration:timestamps command FAILED" && exit 1;
fi
## Check DB
bin/console glpi:database:check_schema \
--config-dir=./tests --ansi --no-interaction \
--config-dir=./tests/config --ansi --no-interaction \
--ignore-dynamic-row-format-migration --ignore-utf8mb4-migration
# Execute dynamic_row_format migration
## Result will depend on DB server/version, we just expect that command will not fail.
bin/console glpi:migration:dynamic_row_format --config-dir=./tests --ansi --no-interaction
bin/console glpi:migration:dynamic_row_format --config-dir=./tests/config --ansi --no-interaction
## Check DB
bin/console glpi:database:check_schema --config-dir=./tests --ansi --no-interaction --ignore-utf8mb4-migration
bin/console glpi:database:check_schema --config-dir=./tests/config --ansi --no-interaction --ignore-utf8mb4-migration
# Execute utf8mb4 migration
## First run should do the migration (with no warnings).
bin/console glpi:migration:utf8mb4 --config-dir=./tests --ansi --no-interaction | tee ~/migration.log
if [[ -n $(grep "Warning\|No migration needed." ~/migration.log) ]];
bin/console glpi:migration:utf8mb4 --config-dir=./tests/config --ansi --no-interaction | tee $LOG_FILE
if [[ -n $(grep "Warning\|No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:migration:utf8mb4 command FAILED" && exit 1;
fi
## Second run should do nothing.
bin/console glpi:migration:utf8mb4 --config-dir=./tests --ansi --no-interaction | tee ~/migration.log
if [[ -z $(grep "No migration needed." ~/migration.log) ]];
bin/console glpi:migration:utf8mb4 --config-dir=./tests/config --ansi --no-interaction | tee $LOG_FILE
if [[ -z $(grep "No migration needed." $LOG_FILE) ]];
then echo "bin/console glpi:migration:utf8mb4 command FAILED" && exit 1;
fi
## Check DB
bin/console glpi:database:check_schema --config-dir=./tests --ansi --no-interaction
bin/console glpi:database:check_schema --config-dir=./tests/config --ansi --no-interaction
# Check updated data
bin/console glpi:database:configure \
--config-dir=./tests --no-interaction --ansi \
--config-dir=./tests/config --no-interaction --ansi \
--reconfigure --db-name=glpi --db-host=db --db-user=root --use-utf8mb4 \
--log-deprecation-warnings
mkdir -p ./tests/files/_cache
tests/bin/test-updated-data --host=db --user=root --fresh-db=glpi --updated-db=glpitest080 --ansi --no-interaction
......@@ -156,11 +156,6 @@ jobs:
if: env.skip != 'true'
run: |
.github/actions/init_show-versions.sh
- name: "Initialize fixtures"
if: env.skip != 'true'
run: |
.github/actions/init_initialize-old-dbs.sh
.github/actions/init_initialize-services-fixtures.sh
- name: "Build dependencies / translations"
if: env.skip != 'true'
run: |
......@@ -172,10 +167,12 @@ jobs:
- name: "Update DB tests (from 0.80, not using utf8mb4)"
if: env.skip != 'true'
run: |
.github/actions/init_initialize-0.80-db.sh
docker-compose exec -T app .github/actions/test_update-from-older-version.sh
- name: "Update DB tests (from 9.5.3, using utf8mb4)"
if: env.skip != 'true'
run: |
.github/actions/init_initialize-9.5.3-db.sh
docker-compose exec -T app .github/actions/test_update-from-9.5.sh
- name: "Unit tests"
if: env.skip != 'true'
......@@ -192,10 +189,12 @@ jobs:
- name: "LDAP tests"
if: env.skip != 'true'
run: |
.github/actions/init_initialize-ldap-fixtures.sh
docker-compose exec -T app .github/actions/test_tests-ldap.sh
- name: "IMAP tests"
if: env.skip != 'true'
run: |
.github/actions/init_initialize-imap-fixtures.sh
docker-compose exec -T app .github/actions/test_tests-imap.sh
- name: "WEB tests"
if: env.skip != 'true'
......
......@@ -22,6 +22,7 @@ phpunit.xml
/tests/code-coverage/
/tests/coverage-*/
/tests/files/
/tests/.env
/tests/glpicrypt.key
/config/based_config.php
/config/config.php
......
......@@ -22,17 +22,17 @@ Creating a dedicated database
-----------------------------
Use the **glpi:database:install** CLI command to create a new database,
only used for the test suite, using the `--config-dir=./tests` option:
only used for the test suite, using the `--config-dir=./tests/config` option:
```bash
$ bin/console glpi:database:install --config-dir=./tests --db-name=glpitests --db-user=root --db-password=xxxx
$ bin/console glpi:database:install --config-dir=./tests/config --db-name=glpitests --db-user=root --db-password=xxxx
Creating the database...
Saving configuration file...
Loading default schema...
Installation done.
```
The configuration file is saved as `tests/config_db.php`.
The configuration file is saved as `tests/config/config_db.php`.
The database is created using the default schema for current version.
......@@ -43,14 +43,17 @@ If you need to recreate the database (e.g. for a new schema), you need to run
Changing database configuration
-------------------------------
Using the same database than the web application is not recommended. Use the `tests/config_db.php` file to adjust connection settings.
Using the same database than the web application is not recommended. Use the `tests/config/config_db.php` file to adjust connection settings.
Running the test suite
----------------------
Running the test suite on developpement env
-------------------------------------------
There are two directories for tests:
- `tests/units` for main core tests;
- `tests/api` for API tests.
There are multiple directories for tests:
- `tests/units` for unit tests;
- `tests/functionnal` for functionnal tests;
- `tests/imap` for Mail collector tests;
- `tests/LDAP` for LDAP connection tests;
- `tests/web` for API tests.
You can choose to run tests on a whole directory, on any file, or on any \<class::method>. You have to specify a bootstrap file each time:
......@@ -85,3 +88,10 @@ Note that if you do not use the `-ncc` switch; coverage will be generated in the
On first run, additional data are loaded into the test database. On following run, this step is skipped. Note that if the test dataset version changes; you'll have to reset your database using the **CliInstall** script again.
Note: you may see a skipped tests regarding missing extension `event`; this is expected ;)
Running the test suite on containerized env
-------------------------------------------
If you want to execute tests in an environment similar to what is done by CI, you can use the `tests/run_tests.sh`.
This scripts requires both "docker" and "docker-compose" utilities to be installed.
Run `tests/run_tests.sh --help` for more information about its usage.
......@@ -32,7 +32,7 @@
*/
define('GLPI_ROOT', dirname(dirname(__DIR__)));
define('GLPI_CONFIG_DIR', GLPI_ROOT . '/tests');
define('GLPI_CONFIG_DIR', GLPI_ROOT . '/tests/config');
define('GLPI_VAR_DIR', GLPI_ROOT . '/tests/files');
define(
'PLUGINS_DIRECTORIES',
......
......@@ -38,7 +38,7 @@ ini_set('display_errors', 'On');
error_reporting(E_ALL);
define('GLPI_ROOT', __DIR__ . '/../');
define('GLPI_CONFIG_DIR', __DIR__);
define('GLPI_CONFIG_DIR', __DIR__ . '/config');
define('GLPI_VAR_DIR', __DIR__ . '/files');
define('GLPI_URI', (getenv('GLPI_URI') ?: 'http://localhost:8088'));
......@@ -58,7 +58,7 @@ global $CFG_GLPI, $GLPI_CACHE;
include (GLPI_ROOT . "/inc/based_config.php");
if (!file_exists(GLPI_CONFIG_DIR . '/config_db.php')) {
die("\nConfiguration file for tests not found\n\nrun: bin/console glpi:database:install --config-dir=./tests ...\n\n");
die("\nConfiguration file for tests not found\n\nrun: bin/console glpi:database:install --config-dir=./tests/config ...\n\n");
}
\GlpiTests\BootstrapUtils::initVarDirectories();
......
......@@ -30,7 +30,7 @@
* ---------------------------------------------------------------------
*/
define('GLPI_CONFIG_DIR', __DIR__);
define('GLPI_CONFIG_DIR', __DIR__ . '/config');
define('GLPI_VAR_DIR', __DIR__ . '/files');
define(
......
#!/bin/bash -e
#
# ---------------------------------------------------------------------
# GLPI - Gestionnaire Libre de Parc Informatique
# Copyright (C) 2015-2021 Teclib' and contributors.
#
# http://glpi-project.org
#
# based on GLPI - Gestionnaire Libre de Parc Informatique
# Copyright (C) 2003-2014 by the INDEPNET Development Team.
#
# ---------------------------------------------------------------------
#
# LICENSE
#
# This file is part of GLPI.
#
# GLPI is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# GLPI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GLPI. If not, see <http://www.gnu.org/licenses/>.
# ---------------------------------------------------------------------
#
WORKING_DIR=$(readlink -f "$(dirname $0)")
# Declaration order in $TESTS_SUITES corresponds to the execution order
TESTS_SUITES=(
"lint"
"install"
"update"
"units"
"functionnal"
"cache"
"ldap"
"imap"
"web"
)
# Extract named options
while [[ $# -gt 0 ]]; do
if [[ $1 == "--"* ]]; then
## Remove -- prefix, replace - by _ and uppercase all
declare $(echo $1 | sed -e 's/^--//g' | sed -e 's/-/_/g' -e 's/\(.*\)/\U\1/')=true
shift
else
break
fi
done
# Extract list of tests suites to run
TESTS_TO_RUN=()
if [[ $# -gt 0 ]]; then
ARGS=("$@")
for KEY in "${ARGS[@]}"; do
INDEX=0
for VALID_KEY in "${TESTS_SUITES[@]}"; do
if [[ "$VALID_KEY" == "$KEY" ]]; then
TESTS_TO_RUN[$INDEX]=$KEY
continue 2 # Go to next arg
fi
INDEX+=1
done
echo -e "\e[1;30;43m/!\ Invalid \"$KEY\" test suite \e[0m"
done
# Ensure install test is executed if something else than "lint" is executed
# This is mandatory as database is initialized by this test suite
if [[ !${#TESTS_TO_RUN[@]} -eq 0 && "${TESTS_TO_RUN[@]}" != "lint" && ! "${TESTS_TO_RUN[@]}" =~ "install" ]]; then
TESTS_TO_RUN=("install" "${TESTS_TO_RUN[@]}")
fi
elif [[ "$ALL" = true ]]; then
TESTS_TO_RUN=("${TESTS_SUITES[@]}")
fi
# Display help if user asks for it, or if it does not provide which test suite has to be executed
if [[ "$HELP" = true || ${#TESTS_TO_RUN[@]} -eq 0 ]]; then
cat << EOF
This command runs the tests in an environment similar to what is done by CI.
Usage: run_tests.sh [options] [tests-suites]
Examples:
- run_tests.sh --all
- run_tests.sh --build ldap imap
- run_tests.sh lint
Available options:
--all run all tests suites
--build build dependencies and translation files before running test suites
Available tests suites:
- lint
- install
- update
- units
- functionnal
- cache
- ldap
- imap
- web
EOF
exit 0
fi
# Check for system dependencies
if [[ ! -x "$(command -v docker)" || ! -x "$(command -v docker-compose)" ]]; then
echo "This scripts requires both \"docker\" and \"docker-compose\" utilities to be installed"
exit 1
fi
# Import variables from .env file this file exists
if [[ -f "$WORKING_DIR/.env" ]]; then
source $WORKING_DIR/.env
fi
# Define variables (some may be defined in .env file)
APPLICATION_ROOT=$(readlink -f "$WORKING_DIR/..")
[[ ! -z "$APP_CONTAINER_HOME" ]] || APP_CONTAINER_HOME=$(mktemp -d -t glpi-tests-home-XXXXXXXXXX)
[[ ! -z "$DB_IMAGE" ]] || DB_IMAGE=githubactions-mysql:8.0
[[ ! -z "$PHP_IMAGE" ]] || PHP_IMAGE=githubactions-php:7.3
# Backup configuration files
BACKUP_DIR=$(mktemp -d -t glpi-tests-backup-XXXXXXXXXX)
find "$APPLICATION_ROOT/tests/config" -mindepth 1 ! -iname ".gitignore" -exec mv {} $BACKUP_DIR \;
# Export variables to env (required for docker-compose) and start containers
export COMPOSE_FILE="$APPLICATION_ROOT/.github/actions/docker-compose-app.yml"
[[ "${TESTS_TO_RUN[@]}" == "lint" ]] || export COMPOSE_FILE="$COMPOSE_FILE:$APPLICATION_ROOT/.github/actions/docker-compose-services.yml"
export APPLICATION_ROOT
export APP_CONTAINER_HOME
export DB_IMAGE
export PHP_IMAGE
cd $WORKING_DIR # Ensure docker-compose will look for .env in current directory