Skip to content

Commit

Permalink
Merge branch 'upgrade-testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
muety committed Dec 6, 2022
2 parents 394215e + f5395e3 commit db6dde3
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 18 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,20 @@ jobs:

- name: Build
run: go build -v .

migration:
name: Migration tests
runs-on: ubuntu-latest

steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.19
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Run sqlite
run: ./testing/run_api_tests.sh sqlite --migration
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ wakapi
build
*.exe
*.db
*.zip
config*.yml
!config.default.yml
!testing/config.testing.yml
Expand Down
89 changes: 71 additions & 18 deletions testing/run_api_tests.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,77 @@
#!/bin/bash

echo "Compiling."
CGO_ENABLED=0 go build

if ! command -v newman &> /dev/null
then
echo "Newman could not be found. Run 'npm install -g newman' first."
exit 1
fi

cd "$(dirname "$0")"
for i in "$@"; do
case $i in
--migration)
MIGRATION=1
shift
;;
esac
done

echo "Creating database and schema ..."
sqlite3 wakapi_testing.db < schema.sql
script_path=$(realpath "${BASH_SOURCE[0]}")
script_dir=$(dirname "$script_path")

echo "Importing seed data ..."
sqlite3 wakapi_testing.db < data.sql
echo "Compiling."
(cd "$script_dir/.." || exit 1; CGO_ENABLED=0 go build)

echo "Running Wakapi testing instance in background ..."
../wakapi -config config.testing.yml &
pid=$!
cd "$script_dir" || exit 1

# Download previous release (when upgrade testing)
initial_run_exe="../wakapi"
if [[ $MIGRATION -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

# Initialise test data
case $1 in
sqlite|*)
rm -f wakapi_testing.db

echo "Waiting for Wakapi to come up ..."
until $(curl --output /dev/null --silent --get --fail http://localhost:3000/api/health); do
printf '.'
echo "Creating database and schema ..."
sqlite3 wakapi_testing.db < schema.sql

echo "Importing seed data ..."
sqlite3 wakapi_testing.db < data.sql

config="config.testing.yml"
;;
esac

wait_for_wakapi () {
counter=0
echo "Waiting for Wakapi to come up ..."
until curl --output /dev/null --silent --get --fail http://localhost:3000/api/health; do
if [ "$counter" -ge 5 ]; then
echo "Waited for 5s, but Wakapi failed to come up ..."
exit 1
fi

printf '.'
sleep 1
counter=$((counter+1))
done
sleep 1
done
printf "\n"
}

echo ""
# Run tests
echo "Running Wakapi testing instance in background ..."
"$initial_run_exe" -config "$config" &
pid=$!
wait_for_wakapi

echo "Running test collection ..."
newman run "wakapi_api_tests.postman_collection.json"
Expand All @@ -36,7 +80,16 @@ exit_code=$?
echo "Shutting down Wakapi ..."
kill -TERM $pid

echo "Deleting database ..."
rm wakapi_testing.db
# 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 db6dde3

Please sign in to comment.