* сделала, чтобы Postgres был доступен только внутри compose-сети
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -29,6 +29,10 @@ from pathlib import Path
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
|
||||
from client import Client, Failure, arguments, check, run # noqa: E402
|
||||
|
||||
# Имя compose-сети проекта: <папка-проекта>_default.
|
||||
# Проверить: docker network ls | findstr default
|
||||
COMPOSE_NETWORK = os.environ.get("COMPOSE_NETWORK", "mtusi2026lab2_default")
|
||||
|
||||
|
||||
# ---------- 1. Конкурентная регистрация одинакового username ----------
|
||||
def test_concurrent_registration(c):
|
||||
@@ -67,16 +71,16 @@ def _read_dsn() -> str:
|
||||
dsn = line.split("=", 1)[1].strip()
|
||||
break
|
||||
check(dsn, "DATABASE_URL не найден ни в окружении, ни в .env")
|
||||
# Внутри контейнера хост — host.docker.internal, а не localhost.
|
||||
return dsn.replace("@localhost:", "@host.docker.internal:").replace(
|
||||
"@127.0.0.1:", "@host.docker.internal:")
|
||||
# Postgres доступен только внутри compose-сети; одноразовые psql-контейнеры
|
||||
# запускаются в этой же сети, поэтому имя хоста postgres резолвится как есть.
|
||||
return dsn
|
||||
|
||||
|
||||
def _psql(dsn_in_container: str, sql: str) -> str:
|
||||
r = subprocess.run(
|
||||
[
|
||||
"docker", "run", "--rm",
|
||||
"--add-host=host.docker.internal:host-gateway",
|
||||
"--network", COMPOSE_NETWORK,
|
||||
"postgres:18-alpine",
|
||||
"psql", dsn_in_container, "-tA", "-c", sql,
|
||||
],
|
||||
@@ -141,7 +145,7 @@ END $$;
|
||||
r = subprocess.run(
|
||||
[
|
||||
"docker", "run", "--rm",
|
||||
"--add-host=host.docker.internal:host-gateway",
|
||||
"--network", COMPOSE_NETWORK,
|
||||
"postgres:18-alpine",
|
||||
"psql", dsn_in_container, "-c", seed_sql,
|
||||
],
|
||||
@@ -173,7 +177,7 @@ END $$;
|
||||
r = subprocess.run(
|
||||
[
|
||||
"docker", "run", "--rm",
|
||||
"--add-host=host.docker.internal:host-gateway",
|
||||
"--network", COMPOSE_NETWORK,
|
||||
"postgres:18-alpine",
|
||||
"psql", dsn_in_container, "-c", sql,
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user