diff --git a/tools/db.sh b/tools/db.sh new file mode 100755 index 0000000..27fe6d3 --- /dev/null +++ b/tools/db.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# +# Start/Stop test databases. +# +# Subcommands: +# start : Start a particular database. +# stop : Stop a particular database. +# +# Usage: +# $ ./tools/db.sh start +# $ ./tools/db.sh stop +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 diff --git a/tools/test.sh b/tools/test.sh new file mode 100755 index 0000000..94826a9 --- /dev/null +++ b/tools/test.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# +# Run tests against a particular database. +# +# Usage: +# $ ./tools/test.sh +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 ./... +