Skip to content

Commit

Permalink
Add a couple helper scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenetriguba committed Aug 18, 2024
1 parent bfa1759 commit a7f3881
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tools/db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
#
# Start/Stop test databases.
#
# Subcommands:
# start <database-name>: Start a particular database.
# stop <database-name>: Stop a particular database.
#
# Usage:
# $ ./tools/db.sh start <database-name>
# $ ./tools/db.sh stop <database-name>
BASE_DIR=`dirname $0`/..
ALLOWED_DB=("postgresql" "mysql" "mssql" "sqlite3")

if [[ ! " ${ALLOWED_DB[@]} " =~ " $2 " ]]; then
echo "Error: Invalid database type. Allowed types are: ${ALLOWED_DB[@]}"
exit 1
fi

case "$1" in
start)
env $(cat "$BASE_DIR/.env.$2" | xargs) docker compose -f "$BASE_DIR/docker-compose.$2.yml" up -d
;;
stop)
env $(cat "$BASE_DIR/.env.$2" | xargs) docker compose -f "$BASE_DIR/docker-compose.$2.yml" down
;;
*)
echo "Error: Invalid command. Use 'start' or 'stop'."
exit 1
;;
esac
16 changes: 16 additions & 0 deletions tools/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
#
# Run tests against a particular database.
#
# Usage:
# $ ./tools/test.sh <database-name>
BASE_DIR=`dirname $0`/..
ALLOWED_DB=("postgresql" "mysql" "mssql" "sqlite3")

if [[ ! " ${ALLOWED_DB[@]} " =~ " $1 " ]]; then
echo "Error: Invalid database type. Allowed types are: ${ALLOWED_DB[@]}"
exit 1
fi

env $(cat "$BASE_DIR/.env.$1" | xargs) go test -p 1 -tags "$1" -cover ./...

0 comments on commit a7f3881

Please sign in to comment.