summaryrefslogtreecommitdiffstats
path: root/tests/integration/run-docker.sh
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2018-08-30 17:12:17 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2018-09-14 23:02:41 +0200
commita1a84c5ed9538bad7725246b253be12317922908 (patch)
tree7c60809440db921c64eec2c00f764d0977eaeafb /tests/integration/run-docker.sh
parentb8b3bd1765a5bfc8b29a89fa23bb25e09491185b (diff)
Make possible to run Docker integration tests on PostgreSQL
Now it is possible to use PostgreSQL as the database when running the integration tests on Docker by calling "run-docker.sh" with the "--database pgsql" option. It is not possible to wait for the PostgreSQL server to be ready using curl like it was done for MySQL; when sending a HTTP request to the PostgreSQL port the server sends an empty response, which curl sees as an error. However, as Bash supports testing a connection with a remote TCP socket, and this approach is valid for both MySQL and PostgreSQL servers, the curl call was replaced with this Bash construct. The default PostgreSQL database image is "postgres:10", the same currently used when running the tests on Drone; a different one can be specified with the "--database-image IMAGE_NAME" option. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'tests/integration/run-docker.sh')
-rwxr-xr-xtests/integration/run-docker.sh22
1 files changed, 17 insertions, 5 deletions
diff --git a/tests/integration/run-docker.sh b/tests/integration/run-docker.sh
index e3ff134e0..0c4ee152b 100755
--- a/tests/integration/run-docker.sh
+++ b/tests/integration/run-docker.sh
@@ -98,15 +98,22 @@ function prepareDatabase() {
DATABASE_PASSWORD=nextcloud
DATABASE_CONTAINER_OPTIONS="--env MYSQL_ROOT_PASSWORD=nextcloud_root --env MYSQL_USER=$DATABASE_USER --env MYSQL_PASSWORD=$DATABASE_PASSWORD --env MYSQL_DATABASE=$DATABASE_NAME"
+ if [ "$DATABASE" = "pgsql" ]; then
+ DATABASE_CONTAINER_OPTIONS=" --env POSTGRES_USER=$DATABASE_USER --env POSTGRES_PASSWORD=$DATABASE_PASSWORD"
+ fi
echo "Starting database server"
docker run --detach --name=$DATABASE_CONTAINER $DATABASE_CONTAINER_OPTIONS $DATABASE_IMAGE
DATABASE_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $DATABASE_CONTAINER)
+
DATABASE_PORT=3306
+ if [ "$DATABASE" = "pgsql" ]; then
+ DATABASE_PORT=5432
+ fi
echo "Waiting for database server to be ready"
- if ! $TIMEOUT 600s bash -c "while ! curl $DATABASE_IP:$DATABASE_PORT >/dev/null 2>&1; do sleep 1; done"; then
+ if ! $TIMEOUT 600s bash -c "while ! (</dev/tcp/$DATABASE_IP/$DATABASE_PORT) >/dev/null 2>&1; do sleep 1; done"; then
echo "Could not start database server after 600 seconds" >&2
exit 1
@@ -207,7 +214,8 @@ if [ "$1" = "--image" ]; then
fi
# "--database XXX" option can be provided to set the database to use to run the
-# integration tests (one of "sqlite" or "mysql"; "sqlite" is used by default).
+# integration tests (one of "sqlite", "mysql" or "pgsql"; "sqlite" is used
+# by default).
DATABASE="sqlite"
if [ "$1" = "--database" ]; then
DATABASE=$2
@@ -215,15 +223,19 @@ if [ "$1" = "--database" ]; then
shift 2
fi
-if [ "$DATABASE" != "sqlite" ] && [ "$DATABASE" != "mysql" ]; then
- echo "--database must be followed by one of: sqlite or mysql"
+if [ "$DATABASE" != "sqlite" ] && [ "$DATABASE" != "mysql" ] && [ "$DATABASE" != "pgsql" ]; then
+ echo "--database must be followed by one of: sqlite, mysql or pgsql"
exit 1
fi
# "--database-image XXX" option can be provided to set the Docker image to use
# for the database container (ignored when using "sqlite").
-DATABASE_IMAGE="mysql:5.7"
+if [ "$DATABASE" = "mysql" ]; then
+ DATABASE_IMAGE="mysql:5.7"
+elif [ "$DATABASE" = "pgsql" ]; then
+ DATABASE_IMAGE="postgres:10"
+fi
if [ "$1" = "--database-image" ]; then
DATABASE_IMAGE=$2