Skip to content

Commit

Permalink
Add and improve tests (#92)
Browse files Browse the repository at this point in the history
* Execute queries with commands in the container
  * Remove `-p 33061:3306` from `container run`
* Change the query result to check as it is
* Add test for `mroonga_command('status')`
  • Loading branch information
abetomo authored Nov 15, 2024
1 parent edbf494 commit b2d27c9
Showing 1 changed file with 43 additions and 19 deletions.
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() {
local sql="$1"
docker container exec "${container_name}" mysql -uroot -sse "${sql}"
}

function assert() {
local expected="$1"
local 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'")"

0 comments on commit b2d27c9

Please sign in to comment.