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:
commit
52d45d4644
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@ -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
|
|
||||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -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
|
||||||
|
1
main.go
1
main.go
@ -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
38
testing/config.mysql.yml
Normal 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
|
39
testing/config.postgres.yml
Normal file
39
testing/config.postgres.yml
Normal 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
|
42
testing/docker-compose.yml
Normal file
42
testing/docker-compose.yml
Normal 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: {}
|
@ -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
|
||||||
@ -35,8 +34,45 @@ if [[ $MIGRATION -eq 1 ]]; then
|
|||||||
echo "Running tests with release version"
|
echo "Running tests with release version"
|
||||||
fi
|
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
|
# 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"
|
||||||
|
|
||||||
|
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|*)
|
sqlite|*)
|
||||||
rm -f wakapi_testing.db
|
rm -f wakapi_testing.db
|
||||||
|
|
||||||
@ -46,7 +82,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 +105,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
|
||||||
|
Loading…
Reference in New Issue
Block a user