diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 11089766bf..0a0b5cc0ad 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -8,6 +8,15 @@ on: branches: - "main" + +env: + POSTGRES_HOST: localhost + POSTGRES_PORT: 5432 + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: prowler_db_test + + jobs: test: runs-on: ubuntu-latest @@ -15,6 +24,26 @@ jobs: matrix: python-version: ["3.12"] + # Service containers to run with `test` + services: + # Label used to access the service container + postgres: + image: postgres + env: + POSTGRES_HOST: ${{ env.POSTGRES_HOST }} + POSTGRES_PORT: ${{ env.POSTGRES_PORT }} + POSTGRES_USER: ${{ env.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }} + POSTGRES_DB: ${{ env.POSTGRES_DB }} + # Set health checks to wait until postgres has started + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - uses: actions/checkout@v4 - name: Test if changes are in not ignored paths diff --git a/src/backend/config/django/testing.py b/src/backend/config/django/testing.py index 07326f7010..b0164b6c9f 100644 --- a/src/backend/config/django/testing.py +++ b/src/backend/config/django/testing.py @@ -5,10 +5,13 @@ from config.env import env DEBUG = env.bool("DJANGO_DEBUG", default=False) ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", default=["localhost", "127.0.0.1"]) -# Database DATABASES = { "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": ":memory:", + "ENGINE": "django.db.backends.postgresql", + "NAME": "prowler_db_test", + "USER": env("POSTGRES_USER", default="prowler"), + "PASSWORD": env("POSTGRES_PASSWORD", default="S3cret"), + "HOST": env("POSTGRES_HOST", default="localhost"), + "PORT": env("POSTGRES_PORT", default="5432"), } }