Skip to content
Snippets Groups Projects
Verified Commit 0815db9e authored by Daniel Göbel's avatar Daniel Göbel
Browse files

Fix tests by adding a mock OIDC provider server to the e2e tests

 * Add mock OIDC provider server to the GitLab pipeline
 * Add check connection script to the start of the service

#10
parent 3e75d0bb
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ before_script: ...@@ -25,7 +25,7 @@ before_script:
- python -m pip install -r requirements.txt - python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt - python -m pip install -r requirements-dev.txt
stages: # List of stages for jobs, and their order of execution stages: # List of stages for jobs, and their order of execution
# - build # - build
- test - test
# - deploy # - deploy
...@@ -36,8 +36,8 @@ stages: # List of stages for jobs, and their order of execution ...@@ -36,8 +36,8 @@ stages: # List of stages for jobs, and their order of execution
# - echo "Compiling the code..." # - echo "Compiling the code..."
# - echo "Compile complete." # - echo "Compile complete."
integration-test-job: # This job runs in the test stage. integration-test-job: # Runs integration tests with the database
stage: test # It only starts when the job in the build stage completes successfully. stage: test
variables: variables:
DB_PASSWORD: "$TEST_DB_PASSWORD" DB_PASSWORD: "$TEST_DB_PASSWORD"
DB_USER: "test_api_user" DB_USER: "test_api_user"
...@@ -64,13 +64,16 @@ integration-test-job: # This job runs in the test stage. ...@@ -64,13 +64,16 @@ integration-test-job: # This job runs in the test stage.
reports: reports:
junit: $BASE_DIR/integration-report.xml junit: $BASE_DIR/integration-report.xml
e2e-test-job: # This job runs in the test stage. e2e-test-job: # Runs e2e tests on the API endpoints
stage: test # It only starts when the job in the build stage completes successfully. stage: test
variables: variables:
DB_PASSWORD: "$TEST_DB_PASSWORD" DB_PASSWORD: "$TEST_DB_PASSWORD"
DB_USER: "test_api_user" DB_USER: "test_api_user"
DB_DATABASE: "e2e-test-db" DB_DATABASE: "e2e-test-db"
DB_HOST: "e2e-test-db" DB_HOST: "e2e-test-db"
OIDC_CLIENT_SECRET: "$TEST_OIDC_CLIENT_SECRET"
OIDC_CLIENT_ID: "$TEST_OIDC_CLIENT_ID"
OIDC_BASE_URI: "http://mock-oidc-server"
services: services:
- name: mysql:8 - name: mysql:8
alias: e2e-test-db alias: e2e-test-db
...@@ -79,8 +82,14 @@ e2e-test-job: # This job runs in the test stage. ...@@ -79,8 +82,14 @@ e2e-test-job: # This job runs in the test stage.
MYSQL_DATABASE: "$DB_DATABASE" MYSQL_DATABASE: "$DB_DATABASE"
MYSQL_USER: "$DB_USER" MYSQL_USER: "$DB_USER"
MYSQL_PASSWORD: "$DB_PASSWORD" MYSQL_PASSWORD: "$DB_PASSWORD"
- name: ghcr.io/soluto/oidc-server-mock:latest
alias: mock-oidc-server
variables:
ASPNETCORE_ENVIRONMENT: "Development"
CLIENTS_CONFIGURATION_INLINE: "$TEST_OIDC_CLIENT_CONFIGURATION"
script: script:
- python app/check_database_connection.py - python app/check_database_connection.py
- python app/check_oidc_connection.py
- alembic downgrade base - alembic downgrade base
- alembic upgrade head - alembic upgrade head
- pytest --junitxml=e2e-report.xml --cov=app --cov-report=term-missing app/tests/api - pytest --junitxml=e2e-report.xml --cov=app --cov-report=term-missing app/tests/api
...@@ -92,8 +101,8 @@ e2e-test-job: # This job runs in the test stage. ...@@ -92,8 +101,8 @@ e2e-test-job: # This job runs in the test stage.
reports: reports:
junit: $BASE_DIR/e2e-report.xml junit: $BASE_DIR/e2e-report.xml
unit-test-job: # This job runs in the test stage. unit-test-job: # Runs unit tests
stage: test # It only starts when the job in the build stage completes successfully. stage: test
script: script:
- pytest --junitxml=unit-report.xml --noconftest --cov=app --cov-report=term-missing app/tests/unit - pytest --junitxml=unit-report.xml --noconftest --cov=app --cov-report=term-missing app/tests/unit
- mkdir coverage-unit - mkdir coverage-unit
...@@ -104,7 +113,7 @@ unit-test-job: # This job runs in the test stage. ...@@ -104,7 +113,7 @@ unit-test-job: # This job runs in the test stage.
reports: reports:
junit: $BASE_DIR/unit-report.xml junit: $BASE_DIR/unit-report.xml
combine-test-coverage-job: # Combine coverage reports from different test jobs combine-test-coverage-job: # Combine coverage reports from different test jobs
stage: test stage: test
needs: needs:
- job: "e2e-test-job" - job: "e2e-test-job"
...@@ -125,8 +134,8 @@ combine-test-coverage-job: # Combine coverage reports from different test jobs ...@@ -125,8 +134,8 @@ combine-test-coverage-job: # Combine coverage reports from different test jobs
coverage_format: cobertura coverage_format: cobertura
path: $CI_PROJECT_DIR/coverage.xml path: $CI_PROJECT_DIR/coverage.xml
lint-test-job: # This job also runs in the test stage. lint-test-job: # Runs linters checks on code
stage: test # It can run at the same time as unit-test-job (in parallel). stage: test
script: script:
- ./scripts/lint.sh - ./scripts/lint.sh
......
import logging
import httpx
from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
from app.core.config import settings
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
max_tries = 60 * 3 # 3 minutes
wait_seconds = 2
@retry(
stop=stop_after_attempt(max_tries),
wait=wait_fixed(wait_seconds),
before=before_log(logger, logging.INFO),
after=after_log(logger, logging.WARN),
)
def init() -> None:
try:
httpx.get(settings.OIDC_BASE_URI + settings.OIDC_META_INFO_PATH, timeout=5.0)
except Exception as e:
logger.error(e)
raise e
def main() -> None:
logger.info("Check OIDC Provider connection")
init()
logger.info("OIDC Provider connection established")
if __name__ == "__main__":
main()
...@@ -20,6 +20,7 @@ omit = [ ...@@ -20,6 +20,7 @@ omit = [
"app/tests/*", "app/tests/*",
"app/check_database_connection.py", "app/check_database_connection.py",
"app/check_ceph_connection.py", "app/check_ceph_connection.py",
"app/check_oidc_connection.py",
"app/db/base*", "app/db/base*",
"app/core/config.py", "app/core/config.py",
"app/main.py" "app/main.py"
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# Check Connection to Ceph RGW # Check Connection to Ceph RGW
python app/check_ceph_connection.py python app/check_ceph_connection.py
# Check Connection to OIDC provider
python app/check_oidc_connection.py
# Let the DB start # Let the DB start
python app/check_database_connection.py python app/check_database_connection.py
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment