mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
ci: upgrade testing for SQLite
This commit is contained in:
parent
0f3b41c2dd
commit
5242df2b7d
17
.github/workflows/ci.yml
vendored
17
.github/workflows/ci.yml
vendored
@ -101,3 +101,20 @@ jobs:
|
|||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go build -v .
|
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 y
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@ wakapi
|
|||||||
build
|
build
|
||||||
*.exe
|
*.exe
|
||||||
*.db
|
*.db
|
||||||
|
*.zip
|
||||||
config*.yml
|
config*.yml
|
||||||
!config.default.yml
|
!config.default.yml
|
||||||
!testing/config.testing.yml
|
!testing/config.testing.yml
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
echo "Compiling."
|
|
||||||
CGO_ENABLED=0 go build
|
|
||||||
|
|
||||||
if ! command -v newman &> /dev/null
|
if ! command -v newman &> /dev/null
|
||||||
then
|
then
|
||||||
@ -9,26 +7,61 @@ then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$(dirname "$0")"
|
script_path=$(realpath "${BASH_SOURCE[0]}")
|
||||||
|
script_dir=$(dirname "$script_path")
|
||||||
|
|
||||||
echo "Creating database and schema ..."
|
echo "Compiling."
|
||||||
sqlite3 wakapi_testing.db < schema.sql
|
(cd "$script_dir/.." || exit 1; CGO_ENABLED=0 go build)
|
||||||
|
|
||||||
echo "Importing seed data ..."
|
cd "$script_dir" || exit 1
|
||||||
sqlite3 wakapi_testing.db < data.sql
|
|
||||||
|
|
||||||
|
# Download previous release (when upgrade testing)
|
||||||
|
INITIAL_RUN_EXE="../wakapi"
|
||||||
|
if [[ "$2" == "y" ]]; then
|
||||||
|
if [ ! -f wakapi_linux_amd64.zip ]; then
|
||||||
|
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 "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
|
||||||
|
printf "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run tests
|
||||||
echo "Running Wakapi testing instance in background ..."
|
echo "Running Wakapi testing instance in background ..."
|
||||||
../wakapi -config config.testing.yml &
|
"$INITIAL_RUN_EXE" -config "$CONFIG" &
|
||||||
pid=$!
|
pid=$!
|
||||||
|
|
||||||
echo "Waiting for Wakapi to come up ..."
|
|
||||||
until $(curl --output /dev/null --silent --get --fail http://localhost:3000/api/health); do
|
|
||||||
printf '.'
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
echo "Running test collection ..."
|
echo "Running test collection ..."
|
||||||
newman run "wakapi_api_tests.postman_collection.json"
|
newman run "wakapi_api_tests.postman_collection.json"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
@ -36,7 +69,16 @@ exit_code=$?
|
|||||||
echo "Shutting down Wakapi ..."
|
echo "Shutting down Wakapi ..."
|
||||||
kill -TERM $pid
|
kill -TERM $pid
|
||||||
|
|
||||||
echo "Deleting database ..."
|
# Run upgrade tests
|
||||||
rm wakapi_testing.db
|
if [[ "$2" == "y" ]]; then
|
||||||
|
echo "Now 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
|
exit $exit_code
|
||||||
|
Loading…
Reference in New Issue
Block a user