aboutsummaryrefslogtreecommitdiffstats
path: root/tools/test.sh
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2025-06-03 23:07:40 -0400
committerEugene Triguba <eugenetriguba@gmail.com>2025-06-03 23:07:40 -0400
commit4eaf7c3908c4fb053ede3ba6e5b788075254c12f (patch)
tree29713897dcb124fb587eca940632d0a29cf5148b /tools/test.sh
parentAdd improvements to db.sh helper script (diff)
downloadcli-4eaf7c3908c4fb053ede3ba6e5b788075254c12f.zip
Tidy up the test.sh tool script
Diffstat (limited to 'tools/test.sh')
-rwxr-xr-xtools/test.sh25
1 files changed, 17 insertions, 8 deletions
diff --git a/tools/test.sh b/tools/test.sh
index 0e9292e..c03678c 100755
--- a/tools/test.sh
+++ b/tools/test.sh
@@ -1,16 +1,25 @@
-#!/bin/sh
+#!/bin/bash
#
# Run tests against a particular database.
#
# Usage:
# $ ./tools/test.sh <database-name>
-BASE_DIR=`dirname $0`/..
-ALLOWED_DB=("postgresql" "mysql" "mssql" "sqlite3")
+set +e
-if [[ ! " ${ALLOWED_DB[@]} " =~ " $1 " ]]; then
- echo "Error: Invalid database type. Allowed types are: ${ALLOWED_DB[@]}"
- exit 1
-fi
+SCRIPT_DIR=$(dirname "$0")
+. "$SCRIPT_DIR/lib.sh"
-env $(cat "$BASE_DIR/.env.$1" | xargs) go test -p 1 -tags "$1" -cover -coverprofile cover.out ./...
+BASE_DIR=$(dirname "$0")/..
+ALLOWED_DBS=("postgresql" "mysql" "mssql" "sqlite3")
+function main() {
+ local DB_NAME="$1"
+ if ! elementIn "$DB_NAME" "${ALLOWED_DBS[@]}"; then
+ echo "Error: Invalid database type. Allowed types are: ${ALLOWED_DBS[*]}" >&2
+ exit 1
+ fi
+
+ env $(cat "$BASE_DIR/.env.$DB_NAME" | xargs) go test -p 1 -tags "$DB_NAME" -cover -coverprofile cover.out ./...
+}
+
+main "$@"