#!/bin/bash set -eu readonly DEFAULT_TESTS="./src/test/*-test.js ./src/routes/test/*-test.js" # clear out any containers if FAST is unset if [[ -z ${FAST+x} ]]; then echo "=> Delete mysql server" docker rm -f mysql-server echo "==> To skip this run with: FAST=1 ./run-tests" else echo "==> WARNING!! Skipping docker container cleanup, the database might not be pristine!" fi # create docker network (while the infra code does this, most tests skip infra setup) docker network create --subnet=172.18.0.0/16 --ip-range=172.18.0.0/20 --gateway 172.18.0.1 cloudron --ipv6 --subnet=fd00:c107:d509::/64 || true # create the same mysql server version to test with OUT=`docker inspect mysql-server` || true if [[ "${OUT}" = "[]" ]]; then echo "=> Starting mysql-server..." # ulimit nofile is required to make it work on archlinux https://github.com/docker-library/mysql/issues/579#issuecomment-519495808 docker run --name mysql-server --ulimit nofile=262144:262144 -e MYSQL_ROOT_PASSWORD=password -d mysql:8.0 else echo "=> mysql-server already running. If you want to start fresh, run 'docker rm --force mysql-server'" fi export MYSQL_IP=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql-server` echo "=> Waiting for mysql server to be ready..." while ! mysqladmin ping -h"${MYSQL_IP}" --silent; do sleep 1 done # echo "=> Create iptables blocklist" # sudo ipset create cloudron_blocklist hash:net || true echo "=> Ensure database" mysql -h"${MYSQL_IP}" -uroot -ppassword -e "ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';" mysql -h"${MYSQL_IP}" -uroot -ppassword -e 'CREATE DATABASE IF NOT EXISTS box' echo "=> Run database migrations" BOX_ENV=test DATABASE_URL=mysql://root:password@${MYSQL_IP}/box node_modules/.bin/db-migrate up TESTS=${DEFAULT_TESTS} if [[ $# -gt 0 ]]; then TESTS="$*" fi echo "=> Run tests" docker run -e BOX_ENV=test -e DATABASE_HOSTNAME=${MYSQL_IP} -v `pwd`:/home/yellowtent/box:ro -v `which node`:/usr/bin/node:ro -v /var/run/docker.sock:/var/run/docker.sock -t cloudron/boxtest node_modules/.bin/mocha --bail --no-timeouts --colors --exit -R spec src/test