diff --git a/Dockerfile b/Dockerfile index 243e520..35a3870 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \ COPY src/ src/ COPY alembic/ alembic/ COPY alembic.ini . +COPY README.md . RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --frozen --no-dev diff --git a/Dockerfile.test b/Dockerfile.test index bdaba0a..42da0f3 100644 --- a/Dockerfile.test +++ b/Dockerfile.test @@ -2,6 +2,7 @@ FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim WORKDIR /app ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy +ENV PATH="/app/.venv/bin:$PATH" COPY pyproject.toml uv.lock ./ RUN --mount=type=cache,target=/root/.cache/uv \ @@ -11,6 +12,7 @@ COPY src/ src/ COPY tests/ tests/ COPY alembic/ alembic/ COPY alembic.ini . +COPY README.md . RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --frozen diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..9c60783 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,26 @@ +services: + postgres: + tmpfs: /var/lib/postgresql/data + ports: [] + volumes: [] + + redis: + ports: [] + + test: + build: + context: . + dockerfile: Dockerfile.test + command: > + sh -c "alembic upgrade head && + pytest tests/ -x -v --tb=short --timeout=30" + environment: + DB_URL: "postgresql+asyncpg://proxypool:proxypool@postgres:5432/proxypool" + REDIS_URL: "redis://redis:6379/1" + SECRET_KEY: "test-secret-key" + LOG_LEVEL: "WARNING" + depends_on: + postgres: + condition: service_healthy + redis: + condition: service_healthy \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 33705bf..6861812 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,8 +40,6 @@ services: POSTGRES_PASSWORD: proxypool ports: - "5432:5432" - volumes: - - pg_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U proxypool"] interval: 2s @@ -56,7 +54,4 @@ services: test: ["CMD", "redis-cli", "ping"] interval: 2s timeout: 5s - retries: 10 - -volumes: - pg_data: \ No newline at end of file + retries: 10 \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index c26811f..7a0132b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,11 +17,19 @@ def event_loop(): @pytest.fixture(scope="session") def test_settings() -> Settings: + import os return Settings( - secret_key="test-secret", - log_level="DEBUG", - db=DatabaseSettings(url="postgresql+asyncpg://proxypool:proxypool@localhost:5432/proxypool"), - redis=RedisSettings(url="redis://localhost:6379"), + secret_key=os.environ.get("SECRET_KEY", "test-secret"), + log_level=os.environ.get("LOG_LEVEL", "DEBUG"), + db=DatabaseSettings( + url=os.environ.get( + "DB_URL", + "postgresql+asyncpg://proxypool:proxypool@localhost:5432/proxypool", + ), + ), + redis=RedisSettings( + url=os.environ.get("REDIS_URL", "redis://localhost:6379/1"), + ), )