feat: optional MySQL/MariaDB database driver for deployments that cannot use local SQLite
This commit is contained in:
1 parent
81e299f09a
commit
d752a61e52
35 files changed
+2896
-76
No files matched your search
@@ -10,6 +10,7 @@ vars:
|
||||
|
||||
env:
|
||||
CGO_ENABLED: '0'
|
||||
__COMPAT_LAYER: RunAsInvoker
|
||||
|
||||
tasks:
|
||||
default:
|
||||
@@ -46,6 +47,46 @@ tasks:
|
||||
cmds:
|
||||
- go test -tags nofrontend ./test/... -count=1 {{.CLI_ARGS}}
|
||||
|
||||
test:mysql:
|
||||
desc: Run the MySQL tests against real servers (mysql:8.4 then mariadb:11 in Docker, removed afterwards)
|
||||
cmds:
|
||||
- cmd: |
|
||||
PASSWORD=renewcms-test-root
|
||||
STATUS=0
|
||||
run_engine() {
|
||||
NAME="renewcms-test-$1"
|
||||
IMAGE="$2"
|
||||
docker rm -f "$NAME" >/dev/null 2>&1
|
||||
docker run -d --name "$NAME" -e MYSQL_ROOT_PASSWORD="$PASSWORD" -p 127.0.0.1::3306 "$IMAGE" >/dev/null || return 1
|
||||
MAPPING="$(docker port "$NAME" 3306/tcp)"
|
||||
PORT="${MAPPING##*:}"
|
||||
READY=no
|
||||
TRIES=0
|
||||
while [ "$TRIES" -lt 90 ]; do
|
||||
if docker exec "$NAME" sh -c "\$(command -v mariadb || command -v mysql) -h127.0.0.1 -uroot -p$PASSWORD -e 'SELECT 1'" >/dev/null 2>&1; then
|
||||
READY=yes
|
||||
break
|
||||
fi
|
||||
TRIES=$((TRIES + 1))
|
||||
sleep 2
|
||||
done
|
||||
if [ "$READY" != yes ]; then
|
||||
echo "$IMAGE did not become ready" >&2
|
||||
docker logs "$NAME" 2>&1 | tail -n 20 >&2
|
||||
docker rm -f "$NAME" >/dev/null 2>&1
|
||||
return 1
|
||||
fi
|
||||
echo "== $IMAGE on 127.0.0.1:$PORT"
|
||||
RENEWCMS_TEST_MYSQL_DSN="root:$PASSWORD@tcp(127.0.0.1:$PORT)/mysql" go test -tags nofrontend ./test/... -run MySQL -count=1 {{.CLI_ARGS}}
|
||||
RESULT=$?
|
||||
docker rm -f "$NAME" >/dev/null 2>&1
|
||||
return $RESULT
|
||||
}
|
||||
run_engine mysql mysql:8.4 || STATUS=1
|
||||
run_engine mariadb mariadb:11 || STATUS=1
|
||||
exit $STATUS
|
||||
silent: true
|
||||
|
||||
cover:
|
||||
desc: Go test coverage of the use cases → tmp/coverage.out
|
||||
cmds:
|
||||
|
||||
Reference in new issue
Block a user