Files
pages/tools/ci/test-mysql.sh
T

42 lines
1.8 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# Native MySQL pilot contracts only, never production data. Reuse a private
# network namespace rather than publishing a port or allocating a new subnet.
suffix="${GITHUB_RUN_ID:-local}-$$-${RANDOM}"
mysql="pageswiki-mysql-test-${suffix}"
tests="pageswiki-mysql-go-${suffix}"
test_image="pageswiki-mysql-test:${suffix}"
cleanup() {
docker rm -fv "$tests" "$mysql" >/dev/null 2>&1 || true
docker image rm "$test_image" >/dev/null 2>&1 || true
}
trap cleanup EXIT
docker build --target source --tag "$test_image" .
docker run --detach --name "$mysql" --network none \
--env MYSQL_ROOT_PASSWORD=pageswiki-synthetic-ci-only \
--env MYSQL_ROOT_HOST=127.0.0.1 \
"${PAGESWIKI_CI_MYSQL_IMAGE:-mysql:8.4}"
ready=false
for ((attempt=0; attempt<60; attempt++)); do
if docker exec --env MYSQL_PWD=pageswiki-synthetic-ci-only "$mysql" \
mysql --protocol=TCP --host=127.0.0.1 --user=root --execute='SELECT 1' >/dev/null 2>&1; then
ready=true
break
fi
sleep 1
done
if [[ "$ready" != true ]]; then
echo 'Synthetic MySQL did not become ready' >&2
exit 1
fi
docker run --rm --name "$tests" --network "container:$mysql" \
--tmpfs /test-tmp:rw,exec,size=2147483648 \
--env TMPDIR=/test-tmp --env GOTMPDIR=/tmp \
--env GOPROXY=off --env GOSUMDB=off \
--env PAGESWIKI_TEST_MYSQL_DSN='root:pageswiki-synthetic-ci-only@tcp(127.0.0.1:3306)/mysql' \
"$test_image" go test -p 1 ./internal/db ./internal/store ./cmd/pageswiki \
-run 'TestMySQL|TestMLBudget|TestMachineLearningPolicyPersistence|TestNamespaceCoreThreeBackendContract|TestStoreNamespaceBackendContract|TestDomainWriteBackend|TestAdminInheritanceBackend|TestGeneralGroupBackend|TestGroupPermissionBackend|TestRoleGrantBackend|TestPrincipalStateBackend|TestAccountBackend' \
-count=1 -v