Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and improve tests #92

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 43 additions & 19 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,55 @@ container_name="mroonga_build_test_${timestamp}"
eval $(grep -E -o '[a-z]+_version=[0-9.]+' $context/Dockerfile)
mysql_version=$(head -n1 $context/Dockerfile | grep -E -o '[0-9.]{2,}')

function run_sql() {
sql="$1"
docker container exec "${container_name}" mysql -uroot -sse "${sql}"
}

function assert() {
expected="$1"
actual="$2"
if [ "${expected}" = "${actual}" ]; then
return 0
fi
echo -e "Not match.\nexpected: <${expected}>\nactual : <${actual}>"
return 1
}

function cleanup() {
sudo docker container stop "${container_name}"
sudo docker container logs "${container_name}"
sudo docker container rm "${container_name}"
}

trap cleanup EXIT
sudo docker container run \
-d \
-p 33061:3306 \
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
--name $container_name \
$image_name

### Should test.
while true ; do
mysqladmin -h 127.0.0.1 -P 33061 -uroot ping && break
docker container exec "${container_name}" mysqladmin -uroot ping && break
sleep 1
done
(echo -e "mroonga_libgroonga_version\t${groonga_version}"; \
echo -e "mroonga_version\t${mroonga_version}"; \
echo -e "version\t${mysql_version}") \
> /tmp/expected.txt
mysql_e="mysql -h 127.0.0.1 -P 33061 -uroot -sse"
($mysql_e "SHOW VARIABLES LIKE 'mroonga_libgroonga_version'"; \
$mysql_e "SHOW VARIABLES LIKE 'mroonga_version'"; \
$mysql_e "SHOW VARIABLES LIKE 'version'") \
> /tmp/actual.txt
set +e
diff -u /tmp/expected.txt /tmp/actual.txt
success=$?
set -e
sudo docker container stop $container_name
sudo docker container logs $container_name
sudo docker container rm $container_name
exit $success

for i in {1..30}; do
# Need to wait a bit until Mroonga is available.
run_sql "SELECT mroonga_command('status')" > /dev/null 2>&1 && break
sleep 1
done

assert \
"\"${groonga_version}\"" \
"$(run_sql "SELECT JSON_EXTRACT(mroonga_command('status'), '$.version')")"
assert \
"mroonga_libgroonga_version ${groonga_version}" \
"$(run_sql "SHOW VARIABLES LIKE 'mroonga_libgroonga_version'")"
assert \
"mroonga_version ${mroonga_version}" \
"$(run_sql "SHOW VARIABLES LIKE 'mroonga_version'")"
assert \
"version ${mysql_version}" \
"$(run_sql "SHOW VARIABLES LIKE 'version'")"
Loading