From ea9eabae50dcbd325797b8eda19d7c1fb98faf5d Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 27 Jul 2015 15:41:06 +0200 Subject: [PATCH] Add possible use of docker instance for MariaDB --- autotest.sh | 55 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/autotest.sh b/autotest.sh index e9327c8f83..0e112bfda3 100755 --- a/autotest.sh +++ b/autotest.sh @@ -21,7 +21,7 @@ DATABASEHOST=localhost ADMINLOGIN=admin$EXECUTOR_NUMBER BASEDIR=$PWD -DBCONFIGS="sqlite mysql pgsql oci" +DBCONFIGS="sqlite mysql mariadb pgsql oci" # $PHP_EXE is run through 'which' and as such e.g. 'php' or 'hhvm' is usually # sufficient. Due to the behaviour of 'which', $PHP_EXE may also be a path @@ -127,7 +127,8 @@ fi echo "Using database $DATABASENAME" function execute_tests { - echo "Setup environment for $1 testing ..." + DB=$1 + echo "Setup environment for $DB testing ..." # back to root folder cd "$BASEDIR" @@ -140,11 +141,43 @@ function execute_tests { cp tests/preseed-config.php config/config.php + _DB=$DB + # drop database - if [ "$1" == "mysql" ] ; then + if [ "$DB" == "mysql" ] ; then mysql -u "$DATABASEUSER" -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true fi - if [ "$1" == "pgsql" ] ; then + if [ "$DB" == "mariadb" ] ; then + if [ ! -z "$USEDOCKER" ] ; then + echo "Fire up the mariadb docker" + DOCKER_CONTAINER_ID=$(docker run \ + -e MYSQL_ROOT_PASSWORD=owncloud \ + -e MYSQL_USER="$DATABASEUSER" \ + -e MYSQL_PASSWORD=owncloud \ + -e MYSQL_DATABASE="$DATABASENAME" \ + -d rullzer/mariadb-owncloud) + DATABASEHOST=$(docker inspect "$DOCKER_CONTAINER_ID" | grep IPAddress | cut -d '"' -f 4) + + echo "Waiting for MariaDB initialisation ..." + + # grep exits on the first match and then the script continues + timeout 30 docker logs -f $DOCKER_CONTAINER_ID 2>&1 | grep -q "mysqld: ready for connections." + + echo "MariaDB is up." + + else + if [ "MariaDB" != "$(mysql --version | grep -o MariaDB)" ] ; then + echo "Your mysql binary is not provided by MariaDB" + echo "To use the docker container set the USEDOCKER enviroment variable" + exit -1 + fi + mysql -u "$DATABASEUSER" -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true + fi + + #Reset _DB to mysql since that is what we use internally + _DB="mysql" + fi + if [ "$DB" == "pgsql" ] ; then if [ ! -z "$USEDOCKER" ] ; then echo "Fire up the postgres docker" DOCKER_CONTAINER_ID=$(docker run -e POSTGRES_USER="$DATABASEUSER" -e POSTGRES_PASSWORD=owncloud -d postgres) @@ -160,7 +193,7 @@ function execute_tests { dropdb -U "$DATABASEUSER" "$DATABASENAME" || true fi fi - if [ "$1" == "oci" ] ; then + if [ "$DB" == "oci" ] ; then echo "Fire up the oracle docker" DOCKER_CONTAINER_ID=$(docker run -d deepdiver/docker-oracle-xe-11g) DATABASEHOST=$(docker inspect "$DOCKER_CONTAINER_ID" | grep IPAddress | cut -d '"' -f 4) @@ -176,20 +209,20 @@ function execute_tests { # trigger installation echo "Installing ...." - "$PHP" ./occ maintenance:install --database="$1" --database-name="$DATABASENAME" --database-host="$DATABASEHOST" --database-user="$DATABASEUSER" --database-pass=owncloud --database-table-prefix=oc_ --admin-user="$ADMINLOGIN" --admin-pass=admin --data-dir="$DATADIR" + "$PHP" ./occ maintenance:install --database="$_DB" --database-name="$DATABASENAME" --database-host="$DATABASEHOST" --database-user="$DATABASEUSER" --database-pass=owncloud --database-table-prefix=oc_ --admin-user="$ADMINLOGIN" --admin-pass=admin --data-dir="$DATADIR" #test execution - echo "Testing with $1 ..." + echo "Testing with $DB ..." cd tests - rm -rf "coverage-html-$1" - mkdir "coverage-html-$1" + rm -rf "coverage-html-$DB" + mkdir "coverage-html-$DB" "$PHP" -f enable_all.php | grep -i -C9999 error && echo "Error during setup" && exit 101 if [ -z "$NOCOVERAGE" ]; then - "${PHPUNIT[@]}" --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" --coverage-clover "autotest-clover-$1.xml" --coverage-html "coverage-html-$1" "$2" "$3" + "${PHPUNIT[@]}" --configuration phpunit-autotest.xml --log-junit "autotest-results-$DB.xml" --coverage-clover "autotest-clover-$DB.xml" --coverage-html "coverage-html-$DB" "$2" "$3" RESULT=$? else echo "No coverage" - "${PHPUNIT[@]}" --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" "$2" "$3" + "${PHPUNIT[@]}" --configuration phpunit-autotest.xml --log-junit "autotest-results-$DB.xml" "$2" "$3" RESULT=$? fi