-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the unit test script strucutre
- Loading branch information
1 parent
2cfef26
commit 4f6ede1
Showing
3 changed files
with
56 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash/ | ||
|
||
container_name=test_users_db | ||
db_user=db_user | ||
db_password=1234 | ||
db_name=users_test_db | ||
|
||
# Run the testing database container | ||
docker run --name $container_name \ | ||
-e POSTGRES_USER=$db_user \ | ||
-e POSTGRES_PASSWORD=$db_password \ | ||
-e POSTGRES_DB=$db_name \ | ||
-p 5432:5432 \ | ||
--health-cmd='pg_isready -d $db_name -U $db_user' \ | ||
--health-interval=10s \ | ||
--health-timeout=5s \ | ||
--health-retries=5 \ | ||
-d postgres:16.1-alpine3.18 | ||
|
||
echo "Waiting for DB..." | ||
|
||
while true; do | ||
# Check the health of the database container | ||
if docker inspect --format '{{json .State.Health.Status}}' $container_name | grep -q "healthy" | ||
then | ||
break | ||
fi | ||
sleep 1 | ||
done | ||
|
||
sleep 30 | ||
|
||
# Run migrations | ||
goose -dir sql/schema postgres postgres://$db_user:$db_password@localhost:5432/$db_name up | ||
|
||
# Run test case | ||
go test ./api/ | ||
|
||
# Stop & remove docker container | ||
docker container stop $container_name | ||
docker container rm $container_name | ||
docker volume prune -a -f |