mirror of
https://github.com/suitenumerique/drive.git
synced 2026-08-17 20:15:40 +02:00
🔧(conf) setup handy local e2e env
We want to be able to quickly start a local isolated env for the e2e testing, we don't want to share to same db with the classic dev env because the e2e db should be empty before tests execution. And we don't want to clear our dev db every time. Also provide a new makefile handy command to launch the e2e env and the tests in one command, great.
This commit is contained in:
@@ -48,6 +48,7 @@ COMPOSE_RUN_CROWDIN = $(COMPOSE_RUN) crowdin crowdin
|
||||
# -- Backend
|
||||
MANAGE = $(COMPOSE_RUN_APP) python manage.py
|
||||
MAIL_YARN = $(COMPOSE_RUN) -w /app/src/mail node yarn
|
||||
PSQL_E2E = ./bin/postgres_e2e
|
||||
|
||||
# -- Frontend
|
||||
PATH_FRONT = ./src/frontend
|
||||
@@ -105,6 +106,7 @@ build-frontend: ## build the frontend container
|
||||
.PHONY: build-frontend-development
|
||||
|
||||
down: ## stop and remove containers, networks, images, and volumes
|
||||
rm -rf data/postgresql.*
|
||||
@$(COMPOSE) down
|
||||
.PHONY: down
|
||||
|
||||
@@ -117,6 +119,33 @@ run-backend: ## start the backend container
|
||||
@$(COMPOSE) up --force-recreate -d nginx
|
||||
.PHONY: run-backend
|
||||
|
||||
bootstrap-e2e: ## bootstrap the backend container for e2e tests, without frontend
|
||||
bootstrap-e2e: \
|
||||
data/media \
|
||||
data/static \
|
||||
create-env-local-files \
|
||||
build-backend \
|
||||
back-i18n-compile \
|
||||
run-backend-e2e
|
||||
.PHONY: bootstrap-e2e
|
||||
|
||||
clear-db-e2e: ## quickly clears the database for e2e tests, used in the e2e tests
|
||||
$(PSQL_E2E) -c "$$(cat bin/clear_db_e2e.sql)"
|
||||
.PHONY: clear-db-e2e
|
||||
|
||||
run-backend-e2e: ## start the backend container for e2e tests, always remove the postgresql.e2e volume first
|
||||
@$(MAKE) stop
|
||||
rm -rf data/postgresql.e2e
|
||||
@ENV_OVERRIDE=e2e $(MAKE) run-backend
|
||||
@ENV_OVERRIDE=e2e $(MAKE) migrate
|
||||
.PHONY: run-backend-e2e
|
||||
|
||||
run-tests-e2e: ## run the e2e tests, example: make run-tests-e2e -- --project chromium --headed
|
||||
@$(MAKE) run-backend-e2e
|
||||
@args="$(filter-out $@,$(MAKECMDGOALS))" && \
|
||||
cd src/frontend/apps/e2e && yarn test $${args:-${1}}
|
||||
.PHONY: run-tests-e2e
|
||||
|
||||
run: ## start the development server and frontend development
|
||||
run:
|
||||
@$(MAKE) run-backend
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
DO $$
|
||||
DECLARE r RECORD;
|
||||
BEGIN
|
||||
FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = 'public')
|
||||
LOOP
|
||||
RAISE NOTICE 'Truncating table %', r.tablename;
|
||||
EXECUTE 'TRUNCATE TABLE ' || quote_ident(r.tablename) || ' CASCADE';
|
||||
END LOOP;
|
||||
END $$;
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# shellcheck source=bin/_config.sh
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/_config.sh"
|
||||
|
||||
# Get database credentials from environment file
|
||||
ENV_FILE="${REPO_DIR}/env.d/development/postgresql.e2e"
|
||||
POSTGRES_USER=$(grep POSTGRES_USER "$ENV_FILE" | cut -d'=' -f2)
|
||||
POSTGRES_DB=$(grep POSTGRES_DB "$ENV_FILE" | cut -d'=' -f2)
|
||||
|
||||
# Execute PostgreSQL command (run as postgres user, not host user)
|
||||
_docker_compose exec -T postgresql psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -v ON_ERROR_STOP=1 "$@"
|
||||
+4
-2
@@ -12,7 +12,9 @@ services:
|
||||
retries: 300
|
||||
env_file:
|
||||
- env.d/development/postgresql
|
||||
- env.d/development/postgresql.local
|
||||
- env.d/development/postgresql.${ENV_OVERRIDE:-local}
|
||||
volumes:
|
||||
- ./data/postgresql.${ENV_OVERRIDE:-local}:/var/lib/postgresql/data
|
||||
|
||||
redis:
|
||||
image: redis:5
|
||||
@@ -71,7 +73,7 @@ services:
|
||||
- env.d/development/common
|
||||
- env.d/development/common.local
|
||||
- env.d/development/postgresql
|
||||
- env.d/development/postgresql.local
|
||||
- env.d/development/postgresql.${ENV_OVERRIDE:-local}
|
||||
ports:
|
||||
- "8071:8000"
|
||||
volumes:
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# Postgresql db container configuration
|
||||
POSTGRES_DB=drive_e2e
|
||||
POSTGRES_USER=dinum
|
||||
POSTGRES_PASSWORD=pass
|
||||
|
||||
# App database configuration
|
||||
DB_HOST=postgresql
|
||||
DB_NAME=drive_e2e
|
||||
DB_USER=dinum
|
||||
DB_PASSWORD=pass
|
||||
DB_PORT=5432
|
||||
Reference in New Issue
Block a user