Skip to content

Commit 7b6bdf7

Browse files
authored
Тест-инфраструктура: compose-стек и исключение интеграционных тестов из CI (#15)
## Что сделано - Коммит 1: локальный docker compose-стек для интеграционных тестов — `compose.yaml` (postgres + redis по умолчанию, minio/minio-init под `--profile files`; те же порты и имена env-переменных, что у бэкенда) + `.env.example` (только плейсхолдеры) + `.env` в `.gitignore`. - Коммит 2: интеграционные тесты исключены из дефолтной сборки и CI — surefire `excludedGroups=integration` (через property, локально переопределяется) + раздел «Тесты» в README (конвенция `@Tag(\"integration\")\", локальный запуск ИТ, поведение в CI). ## Проверки - `docker compose config` (оба профиля) — валидно. - `mvn test` — 27 unit-тестов, зелёное, интеграционных в прогоне нет. - Явный запуск по тегу (`mvn test -Dgroups=integration -DexcludedGroups=`) отдельно проверен на соседней ветке против живого бэкенда.
1 parent 5d685cd commit 7b6bdf7

5 files changed

Lines changed: 132 additions & 0 deletions

File tree

‎.env.example‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Example environment for the local test infrastructure (see compose.yaml).
2+
# Copy to .env (gitignored, never commit real secrets):
3+
# cp .env.example .env
4+
5+
# --- Postgres ---
6+
POSTGRES_DB=pks_dev
7+
POSTGRES_USER=pks_user
8+
POSTGRES_PASSWORD=changeme
9+
10+
# --- Backend app settings (used by the backend, not by compose) ---
11+
APP_PORT=8080
12+
REDIS_PASSWORD=changeme
13+
14+
# --- MinIO (only needed with: docker compose --profile files up -d) ---
15+
MINIO_ROOT_USER=minioadmin
16+
MINIO_ROOT_PASSWORD=changeme-minio-root
17+
MINIO_BUCKET_NAME=local-bucket
18+
MINIO_ACCESS_TOKEN=changeme-access
19+
MINIO_SECRET_KEY=changeme-secret

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# Log file
55
*.log
66

7+
# Local environment (see .env.example, never commit real secrets)
8+
.env
9+
710
# BlueJ files
811
*.ctxt
912

‎README.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,25 @@ git pull --rebase
1111
```plain
1212
Пользователь (USER) <- Модератор (MODER) <- Администратор (ADMIN)
1313
```
14+
15+
## Тесты
16+
17+
Два вида тестов:
18+
19+
- **Unit** (`mvn test`): API мокается, внешнего бэкенда не нужно.
20+
- **Integration** (классы с `@Tag("integration")`): ходят в живой API без моков,
21+
им нужен поднятый бэкенд. Из дефолтной сборки и из CI они исключены
22+
(surefire `excludedGroups` в `pom.xml`), чтобы джобы не падали без бэкенда.
23+
24+
Локальный запуск интеграционных тестов:
25+
26+
```bash
27+
cp .env.example .env
28+
docker compose up -d
29+
# для файловых/экспортных тестов: docker compose --profile files up -d
30+
31+
# запустить бэкенд из соседнего репозитория (порт 8080 из APP_PORT):
32+
# cd ../pks-java && ./mvnw spring-boot:run
33+
34+
mvn test -Dgroups=integration -DexcludedGroups=
35+
```

‎compose.yaml‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Test infrastructure for DesktopApplicationClientJava integration tests.
2+
#
3+
# Mirrors the contract of the backend (pks-java) compose file: same services,
4+
# same ports, same environment variable names (see .env.example).
5+
# Run only ONE stack at a time (this one OR the backend one) — ports overlap.
6+
#
7+
# Default: postgres + redis (enough for auth/resource/user/admin ITs):
8+
# docker compose up -d
9+
# With object storage (for file/export ITs):
10+
# docker compose --profile files up -d
11+
12+
services:
13+
postgres:
14+
image: postgres:16-alpine
15+
environment:
16+
- POSTGRES_DB=${POSTGRES_DB}
17+
- POSTGRES_USER=${POSTGRES_USER}
18+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
19+
ports:
20+
- '5432:5432'
21+
volumes:
22+
- postgres_data:/var/lib/postgresql/data
23+
restart: unless-stopped
24+
healthcheck:
25+
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
26+
interval: 10s
27+
timeout: 5s
28+
retries: 5
29+
30+
redis:
31+
image: redis:7-alpine
32+
ports:
33+
- '6379:6379'
34+
volumes:
35+
- redis_basic_data:/data
36+
restart: unless-stopped
37+
healthcheck:
38+
test: ["CMD", "redis-cli", "ping"]
39+
interval: 10s
40+
timeout: 5s
41+
retries: 5
42+
43+
minio:
44+
image: quay.io/minio/minio
45+
profiles: [files]
46+
command: server /data --console-address ":9001"
47+
environment:
48+
- MINIO_ROOT_USER=${MINIO_ROOT_USER}
49+
- MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD}
50+
ports:
51+
- '9000:9000' # S3 API
52+
- '9001:9001' # Web Console
53+
volumes:
54+
- minio_data:/data
55+
restart: unless-stopped
56+
healthcheck:
57+
test: ["CMD-SHELL", "curl -f http://localhost:9000/minio/health/live || exit 1"]
58+
interval: 10s
59+
timeout: 5s
60+
retries: 5
61+
62+
minio-init:
63+
image: minio/mc:latest
64+
profiles: [files]
65+
depends_on:
66+
minio:
67+
condition: service_healthy
68+
entrypoint: >
69+
/bin/sh -c "
70+
mc alias set myminio http://minio:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD};
71+
mc mb myminio/${MINIO_BUCKET_NAME} --ignore-existing;
72+
mc admin user add myminio ${MINIO_ACCESS_TOKEN} ${MINIO_SECRET_KEY};
73+
mc admin policy attach myminio readwrite --user ${MINIO_ACCESS_TOKEN};
74+
exit 0;
75+
"
76+
77+
volumes:
78+
redis_basic_data:
79+
postgres_data:
80+
driver: local
81+
minio_data:
82+
driver: local

‎pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<encoding>UTF-8</encoding>
1919
<project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
2020
<project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>
21+
<excludedGroups>integration</excludedGroups>
2122
</properties>
2223

2324
<dependencyManagement>
@@ -134,6 +135,11 @@
134135
-Djava.awt.headless=true
135136
--enable-native-access=ALL-UNNAMED
136137
</argLine>
138+
<!-- Integration tests (tag "integration") need a live backend,
139+
so they never run in the default build or CI.
140+
Run them explicitly:
141+
mvn test -Dgroups=integration -DexcludedGroups= -->
142+
<excludedGroups>${excludedGroups}</excludedGroups>
137143
</configuration>
138144
</plugin>
139145
<plugin>

0 commit comments

Comments
 (0)