Skip to content

Commit

Permalink
fix: run api tests ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
YC committed Nov 17, 2023
1 parent 38cb6dc commit 7e179a1
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions testing/run_api_tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash
set -o nounset -o pipefail -o errexit

if ! command -v newman &> /dev/null
then
DB_TYPE=${1-sqlite}

if ! command -v newman &> /dev/null; then
echo "Newman could not be found. Run 'npm install -g newman' first."
exit 1
fi
Expand All @@ -23,14 +25,12 @@ echo "Compiling."
cd "$script_dir" || exit 1

# Download previous release (when upgrade testing)
initial_run_exe="../wakapi"
if [[ $MIGRATION -eq 1 ]]; then
if [ "${MIGRATION-0}" -eq 1 ]; then
if [ ! -f wakapi_linux_amd64.zip ]; then
echo "Downloading latest release"
curl https://github.com/muety/wakapi/releases/latest/download/wakapi_linux_amd64.zip -O -L
fi
unzip -o wakapi_linux_amd64.zip
initial_run_exe="./wakapi"
echo "Running tests with release version"
fi

Expand All @@ -45,22 +45,22 @@ cleanup() {
trap cleanup EXIT

# Initialise test data
case $1 in
case $DB_TYPE in
postgres|mysql|mariadb|cockroach)
docker compose -f "$script_dir/docker-compose.yml" down

docker_down=1
docker compose -f "$script_dir/docker-compose.yml" up --wait -d "$1"
docker compose -f "$script_dir/docker-compose.yml" up --wait --detach "$DB_TYPE"

config="config.$1.yml"
if [ "$1" == "mariadb" ]; then
config="config.$DB_TYPE.yml"
if [ "$DB_TYPE" == "mariadb" ]; then
config="config.mysql.yml"
fi

db_port=0
if [ "$1" == "postgres" ]; then
if [ "$DB_TYPE" == "postgres" ]; then
db_port=55432
elif [ "$1" == "cockroach" ]; then
elif [ "$DB_TYPE" == "cockroach" ]; then
db_port=56257
else
db_port=26257
Expand Down Expand Up @@ -104,14 +104,24 @@ wait_for_wakapi () {
printf "\n"
}

# Run tests
echo "Running Wakapi testing instance in background ..."
# Run original wakapi
echo "Configuration file: $config"
"$initial_run_exe" -config "$config" &
if [ "${MIGRATION-0}" -eq 1 ]; then
echo "Running last release ..."
./wakapi -config "$config" &
pid=$!
wait_for_wakapi

echo "Shutting down Wakapi ..."
kill -TERM $pid
fi

echo "Running current build ..."
../wakapi -config "$config" &
pid=$!
wait_for_wakapi

if [ "$1" == "sqlite" ] || [ -z "$1" ]; then
if [ "$DB_TYPE" == "sqlite" ]; then
echo "Running test collection ..."
newman run "wakapi_api_tests.postman_collection.json"
exit_code=$?
Expand All @@ -122,16 +132,5 @@ fi
echo "Shutting down Wakapi ..."
kill -TERM $pid

# Run upgrade tests
if [[ $MIGRATION -eq 1 ]]; then
echo "Running migrations with build"
../wakapi -config "$config" &
pid=$!

wait_for_wakapi
echo "Shutting down Wakapi ..."
kill -TERM $pid
fi

echo "Exiting with status $exit_code"
exit $exit_code

0 comments on commit 7e179a1

Please sign in to comment.