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

test: migration testing for mysql/mariadb/postgres

This commit is contained in:
Steven Tang 2022-12-27 14:39:32 +11:00
parent cd5c511474
commit ad704cef5c
No known key found for this signature in database
GPG Key ID: 1597520C734BAE66
8 changed files with 159 additions and 9 deletions

View File

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

2
.gitignore vendored
View File

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

View File

@ -132,6 +132,7 @@ func main() {
// Connect to database // Connect to database
var err error 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)) db, err = gorm.Open(config.Db.GetDialector(), &gorm.Config{Logger: gormLogger}, conf.GetWakapiDBOpts(&config.Db))
if err != nil { if err != nil {
logbuch.Error(err.Error()) 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: 3306
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: 5432
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"
ports:
- "5432:5432"
volumes:
- wakapi-postgres:/var/lib/postgresql/data
mysql:
image: mysql:8
environment:
MYSQL_USER: "wakapi"
MYSQL_PASSWORD: "wakapi"
MYSQL_DATABASE: "wakapi"
MYSQL_ROOT_PASSWORD: example
ports:
- "3306:3306"
volumes:
- wakapi-mysql:/var/lib/mysql
mariadb:
image: mariadb:10
environment:
MARIADB_USER: "wakapi"
MARIADB_PASSWORD: "wakapi"
MARIADB_DATABASE: "wakapi"
MARIADB_ROOT_PASSWORD: example
ports:
- "3306:3306"
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 case $i in
--migration) --migration)
MIGRATION=1 MIGRATION=1
shift
;; ;;
esac esac
done done
@ -37,6 +36,24 @@ fi
# Initialise test data # Initialise test data
case $1 in 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"
if [ "$1" == "mariadb" ]; then
config="config.mysql.yml"
else
config="config.$1.yml"
fi
sleep 5
if [ "$1" == "mysql" ]; then
sleep 10
fi
;;
sqlite|*) sqlite|*)
rm -f wakapi_testing.db rm -f wakapi_testing.db
@ -46,7 +63,7 @@ case $1 in
echo "Importing seed data ..." echo "Importing seed data ..."
sqlite3 wakapi_testing.db < data.sql sqlite3 wakapi_testing.db < data.sql
config="config.testing.yml" config="config.sqlite.yml"
;; ;;
esac esac
@ -69,13 +86,18 @@ wait_for_wakapi () {
# Run tests # Run tests
echo "Running Wakapi testing instance in background ..." echo "Running Wakapi testing instance in background ..."
echo "Configuration file: $config"
"$initial_run_exe" -config "$config" & "$initial_run_exe" -config "$config" &
pid=$! pid=$!
wait_for_wakapi wait_for_wakapi
echo "Running test collection ..." if [ "$1" == "sqlite" ]; then
newman run "wakapi_api_tests.postman_collection.json" echo "Running test collection ..."
exit_code=$? newman run "wakapi_api_tests.postman_collection.json"
exit_code=$?
else
exit_code=0
fi
echo "Shutting down Wakapi ..." echo "Shutting down Wakapi ..."
kill -TERM $pid kill -TERM $pid
@ -91,5 +113,9 @@ if [[ $MIGRATION -eq 1 ]]; then
kill -TERM $pid kill -TERM $pid
fi fi
if [ "$docker_down" -eq 1 ]; then
docker compose -f "$script_dir/docker-compose.yml" down
fi
echo "Exiting with status $exit_code" echo "Exiting with status $exit_code"
exit $exit_code exit $exit_code