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 2 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
49 changes: 37 additions & 12 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,54 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sql=$1
sql="$1"

docker container exec "${container_name}" mysql -uroot -sse "${sql}"
}

function assert() {
expected=$1
actual=$2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expected=$1
actual=$2
expected="$1"
actual="$2"

if [ "$(echo ${expected})" = "$(echo ${actual})" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なんでechoいるの?

Suggested change
if [ "$(echo ${expected})" = "$(echo ${actual})" ]; then
if [ "${expected}" = "${actual}" ]; then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo いらないです。見た目が同じ文字列が = 判定されなくて色々検証していた残骸です…。
= 判定されなかったのは \t じゃなくて (ただのスペース)だったからでした。)

return 0
fi
echo -e "Not match.\nexpected: <${expected}>\nactual : <${actual}>"
return 1
}

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

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

set +e
diff -u /tmp/expected.txt /tmp/actual.txt
echo -e "$(run_sql "SELECT JSON_PRETTY(mroonga_command('status'))")" && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo -eってなんで必要なの?\nを改行にしたいとか?

Suggested change
echo -e "$(run_sql "SELECT JSON_PRETTY(mroonga_command('status'))")" && \
run_sql "SELECT JSON_PRETTY(mroonga_command('status'))" && \

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうですね。
echo しないと {\n "os": "Linux",\n "cpu": "x86_64",\n ... という感じだったので付けました。
そもそもこの表示がいらないか。

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'")"
success=$?

set -e
sudo docker container stop $container_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こいつらをtrap EXITでやるようにしたら↑の&&はなくせる?

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ぉぉ、これ探してたんですよ!試してみます。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あざます。できました。

sudo docker container logs $container_name
Expand Down
Loading