diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2025-06-03 23:07:40 -0400 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2025-06-03 23:07:40 -0400 |
| commit | 4eaf7c3908c4fb053ede3ba6e5b788075254c12f (patch) | |
| tree | 29713897dcb124fb587eca940632d0a29cf5148b | |
| parent | Add improvements to db.sh helper script (diff) | |
| download | cli-4eaf7c3908c4fb053ede3ba6e5b788075254c12f.zip | |
Tidy up the test.sh tool script
| -rwxr-xr-x | tools/db.sh | 18 | ||||
| -rw-r--r-- | tools/lib.sh | 16 | ||||
| -rwxr-xr-x | tools/test.sh | 25 |
3 files changed, 36 insertions, 23 deletions
diff --git a/tools/db.sh b/tools/db.sh index c554e48..8e6f2b9 100755 --- a/tools/db.sh +++ b/tools/db.sh @@ -11,6 +11,9 @@ # $ ./tools/db.sh stop <database-name> set +e +SCRIPT_DIR=$(dirname "$0") +. "$SCRIPT_DIR/lib.sh" + BASE_DIR=$(dirname "$0")/.. ALLOWED_DBS=("postgresql" "mysql" "mssql") ALLOWED_COMMANDS=("start" "stop") @@ -41,19 +44,4 @@ function main() { esac } -# elementIn checks whether a element is in an array. -# -# Args: -# $1: The element -# $2: The array -# -# Returns: -# 0 if the element is in the array; 1 otherwise. -function elementIn() { - local e match="$1" - shift - for e; do [[ "$e" == "$match" ]] && return 0; done - return 1 -} - main "$@" diff --git a/tools/lib.sh b/tools/lib.sh new file mode 100644 index 0000000..e2c2c78 --- /dev/null +++ b/tools/lib.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# elementIn checks whether a element is in an array. +# +# Args: +# $1: The element +# $2: The array +# +# Returns: +# 0 if the element is in the array; 1 otherwise. +function elementIn() { + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} 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 "$@" |