From a7f3881536b2fb56b10b74af32172227633bd691 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 18 Aug 2024 15:10:05 -0400 Subject: [PATCH] Add a couple helper scripts --- tools/db.sh | 31 +++++++++++++++++++++++++++++++ tools/test.sh | 16 ++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 tools/db.sh create mode 100755 tools/test.sh 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 ./... +