1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Merge pull request #448 from muety/test-migrations

Basic migration tests for mysql/mariadb/postgres
This commit is contained in:
Ferdinand Mütsch 2022-12-27 15:35:45 +01:00 committed by GitHub
commit 52d45d4644
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 174 additions and 9 deletions

View File

@ -106,6 +106,11 @@ jobs:
name: Migration tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
db: [sqlite, postgres, mysql, mariadb]
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
@ -116,5 +121,4 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Run sqlite
run: ./testing/run_api_tests.sh sqlite --migration
- run: ./testing/run_api_tests.sh ${{ matrix.db }} --migration

2
.gitignore vendored
View File

@ -8,7 +8,7 @@ build
*.zip
config*.yml
!config.default.yml
!testing/config.testing.yml
!testing/config.*.yml
pkged.go
package-lock.json
node_modules

View File

@ -132,6 +132,7 @@ func main() {
// Connect to database
var err error
logbuch.Info("starting with %s database", config.Db.Dialect)
db, err = gorm.Open(config.Db.GetDialector(), &gorm.Config{Logger: gormLogger}, conf.GetWakapiDBOpts(&config.Db))
if err != nil {
logbuch.Error(err.Error())

38
testing/config.mysql.yml Normal file
View File

@ -0,0 +1,38 @@
env: production
server:
listen_ipv4: 127.0.0.1
listen_ipv6:
tls_cert_path:
tls_key_path:
port: 3000
base_path: /
public_url: http://localhost:3000
app:
aggregation_time: '02:15'
report_time_weekly: 'fri,18:00'
heartbeat_max_age: 87600h # 10 years
inactive_days: 7
custom_languages:
vue: Vue
jsx: JSX
svelte: Svelte
db:
host: 127.0.0.1
port: 53306
user: wakapi
password: wakapi
name: wakapi
dialect: mysql
max_conn: 2
ssl: false
automgirate_fail_silently: false
security:
password_salt:
insecure_cookies: true
cookie_max_age: 172800
allow_signup: true
expose_metrics: true

View File

@ -0,0 +1,39 @@
env: production
server:
listen_ipv4: 127.0.0.1
listen_ipv6:
tls_cert_path:
tls_key_path:
port: 3000
base_path: /
public_url: http://localhost:3000
app:
aggregation_time: '02:15'
report_time_weekly: 'fri,18:00'
heartbeat_max_age: 87600h # 10 years
inactive_days: 7
custom_languages:
vue: Vue
jsx: JSX
svelte: Svelte
db:
host: 127.0.0.1
port: 55432
user: wakapi
password: wakapi
name: wakapi
dialect: postgres
charset:
max_conn: 2
ssl: false
automgirate_fail_silently: false
security:
password_salt:
insecure_cookies: true
cookie_max_age: 172800
allow_signup: true
expose_metrics: true

View File

@ -0,0 +1,42 @@
version: '3.7'
services:
postgres:
image: postgres:15
environment:
POSTGRES_USER: "wakapi"
POSTGRES_PASSWORD: "wakapi"
POSTGRES_DB: "wakapi"
PGPORT: 55432
network_mode: host
volumes:
- wakapi-postgres:/var/lib/postgresql/data
mysql:
image: mysql:8
environment:
MYSQL_TCP_PORT: 53306
MYSQL_USER: "wakapi"
MYSQL_PASSWORD: "wakapi"
MYSQL_DATABASE: "wakapi"
MYSQL_ROOT_PASSWORD: example
network_mode: host
volumes:
- wakapi-mysql:/var/lib/mysql
mariadb:
image: mariadb:10
environment:
MYSQL_TCP_PORT: 53306
MARIADB_USER: "wakapi"
MARIADB_PASSWORD: "wakapi"
MARIADB_DATABASE: "wakapi"
MARIADB_ROOT_PASSWORD: example
network_mode: host
volumes:
- wakapi-mariadb:/var/lib/mysql
volumes:
wakapi-postgres: {}
wakapi-mysql: {}
wakapi-mariadb: {}

View File

@ -10,7 +10,6 @@ for i in "$@"; do
case $i in
--migration)
MIGRATION=1
shift
;;
esac
done
@ -35,8 +34,45 @@ if [[ $MIGRATION -eq 1 ]]; then
echo "Running tests with release version"
fi
cleanup() {
if [ -n "$pid" ] && ps -p "$pid" > /dev/null; then
kill -TERM "$pid"
fi
if [ "${docker_down-0}" -eq 1 ]; then
docker compose -f "$script_dir/docker-compose.yml" down
fi
}
trap cleanup EXIT
# Initialise test data
case $1 in
postgres|mysql|mariadb)
docker compose -f "$script_dir/docker-compose.yml" down
docker volume rm "testing_wakapi-$1"
docker_down=1
docker compose -f "$script_dir/docker-compose.yml" up --wait -d "$1"
config="config.$1.yml"
if [ "$1" == "mariadb" ]; then
config="config.mysql.yml"
fi
db_port=0
if [ "$1" == "postgres" ]; then
db_port=55432
else
db_port=53306
fi
for _ in $(seq 0 30); do
if netstat -tulpn 2>/dev/null | grep "LISTEN" | tr -s ' ' | cut -d' ' -f4 | grep -E ":$db_port$" > /dev/null; then
break
fi
sleep 1
done
;;
sqlite|*)
rm -f wakapi_testing.db
@ -46,7 +82,7 @@ case $1 in
echo "Importing seed data ..."
sqlite3 wakapi_testing.db < data.sql
config="config.testing.yml"
config="config.sqlite.yml"
;;
esac
@ -69,13 +105,18 @@ wait_for_wakapi () {
# Run tests
echo "Running Wakapi testing instance in background ..."
echo "Configuration file: $config"
"$initial_run_exe" -config "$config" &
pid=$!
wait_for_wakapi
if [ "$1" == "sqlite" ]; then
echo "Running test collection ..."
newman run "wakapi_api_tests.postman_collection.json"
exit_code=$?
else
exit_code=0
fi
echo "Shutting down Wakapi ..."
kill -TERM $pid