mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 15:12:08 +01:00
fix(tests): fixed testing DB deployment v3
This commit is contained in:
35
.github/workflows/run-tests.yml
vendored
35
.github/workflows/run-tests.yml
vendored
@@ -22,36 +22,33 @@ jobs:
|
|||||||
build-and-test:
|
build-and-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
# 1) Start a MariaDB service container for tests
|
|
||||||
services:
|
services:
|
||||||
# The label 'mariadb' becomes the hostname
|
|
||||||
mariadb:
|
mariadb:
|
||||||
image: mariadb:11.4
|
image: mariadb:11.4
|
||||||
env:
|
env:
|
||||||
MARIADB_ROOT_PASSWORD: rootpw
|
MARIADB_ROOT_PASSWORD: rootpw
|
||||||
# This DB name now matches what your app expects
|
MARIADB_DATABASE: group_project # Using the DB name your app expects
|
||||||
MARIADB_DATABASE: group_project
|
|
||||||
MARIADB_USER: appuser
|
MARIADB_USER: appuser
|
||||||
MARIADB_PASSWORD: apppass
|
MARIADB_PASSWORD: apppass
|
||||||
# 'ports' and 'options' are removed.
|
# ADD THIS BLOCK BACK IN
|
||||||
# GitHub Actions will use the image's default healthcheck.
|
# This forces the job to wait until the DB is
|
||||||
|
# actually responding before continuing.
|
||||||
|
options: >-
|
||||||
|
--health-cmd="mysqladmin ping -h 127.0.0.1 -u root -prootpw --silent"
|
||||||
|
--health-interval=5s
|
||||||
|
--health-timeout=2s
|
||||||
|
--health-retries=20
|
||||||
|
|
||||||
# 2) Expose DB connection settings to steps
|
# This is the job-level 'env' block
|
||||||
|
# It will be used by the 'alembic' step
|
||||||
env:
|
env:
|
||||||
# Use the service label 'mariadb' as the host
|
MARIADB_HOST: mariadb # Use the service label as the host
|
||||||
MARIADB_HOST: mariadb
|
MARIADB_PORT: "3306"
|
||||||
MARIADB_PORT: "3306" # This is the internal port, which is correct
|
|
||||||
# Match the database name from the service
|
|
||||||
MARIADB_DB: group_project
|
MARIADB_DB: group_project
|
||||||
MARIADB_USER: appuser
|
MARIADB_USER: appuser
|
||||||
MARIADB_PASSWORD: apppass
|
MARIADB_PASSWORD: apppass
|
||||||
|
|
||||||
# -----------------
|
|
||||||
# ----- Steps -----
|
|
||||||
# -----------------
|
|
||||||
steps:
|
steps:
|
||||||
# ... (your steps remain the same) ...
|
|
||||||
|
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -65,15 +62,19 @@ jobs:
|
|||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
# This step will now wait for the healthcheck to pass
|
||||||
|
# and will use the job-level 'env' block
|
||||||
- name: Run Alembic migrations
|
- name: Run Alembic migrations
|
||||||
run: |
|
run: |
|
||||||
alembic upgrade head
|
alembic upgrade head
|
||||||
working-directory: ./7project/backend
|
working-directory: ./7project/backend
|
||||||
|
|
||||||
|
# This step-level 'env' block overrides any local .env
|
||||||
|
# file that your pytest setup might be loading
|
||||||
- name: Run tests with pytest
|
- name: Run tests with pytest
|
||||||
env:
|
env:
|
||||||
MARIADB_HOST: mariadb
|
MARIADB_HOST: mariadb
|
||||||
MARIADB_DB: group_project # Make sure this matches the service DB
|
MARIADB_DB: group_project
|
||||||
MARIADB_USER: appuser
|
MARIADB_USER: appuser
|
||||||
MARIADB_PASSWORD: apppass
|
MARIADB_PASSWORD: apppass
|
||||||
run: pytest
|
run: pytest
|
||||||
|
|||||||
Reference in New Issue
Block a user