feat: enhance service discovery and proxy management
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
from pathlib import Path
|
||||
|
||||
from integrations.docker.compose import get_all_services_in_dir
|
||||
|
||||
|
||||
def test_get_all_services_in_dir_scans_immediate_children(tmp_path: Path):
|
||||
root = tmp_path / "workspace"
|
||||
project = root / "playground"
|
||||
project.mkdir(parents=True)
|
||||
(project / "docker-compose.yml").write_text(
|
||||
"""
|
||||
services:
|
||||
echo:
|
||||
image: hashicorp/http-echo:1.0
|
||||
ports:
|
||||
- "9081:5678"
|
||||
""".strip(),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
services = get_all_services_in_dir(root)
|
||||
|
||||
assert services == [
|
||||
{
|
||||
"name": "echo",
|
||||
"ports": [9081],
|
||||
"bindings": [{"published": 9081, "host": None}],
|
||||
"folder": project,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_get_all_services_in_dir_skips_nested_grandchildren(tmp_path: Path):
|
||||
root = tmp_path / "workspace"
|
||||
nested = root / "group" / "playground"
|
||||
nested.mkdir(parents=True)
|
||||
(nested / "docker-compose.yml").write_text(
|
||||
"""
|
||||
services:
|
||||
echo:
|
||||
image: hashicorp/http-echo:1.0
|
||||
ports:
|
||||
- "9081:5678"
|
||||
""".strip(),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
services = get_all_services_in_dir(root)
|
||||
|
||||
assert services == []
|
||||
@@ -0,0 +1,30 @@
|
||||
from integrations.docker.ports import _get_service_binding, _replace_port_in_mapping
|
||||
|
||||
|
||||
def test_get_service_binding_includes_loopback_hosts():
|
||||
assert _get_service_binding("127.0.0.1:8080:80") == (8080, "127.0.0.1")
|
||||
assert _get_service_binding("localhost:9081:5678") == (9081, "localhost")
|
||||
|
||||
|
||||
def test_replace_port_in_mapping_can_force_loopback_host():
|
||||
updated = _replace_port_in_mapping(
|
||||
"9081:5678",
|
||||
9081,
|
||||
54001,
|
||||
host_to="127.0.0.1",
|
||||
rewrite_host=True,
|
||||
)
|
||||
|
||||
assert updated == "127.0.0.1:54001:5678"
|
||||
|
||||
|
||||
def test_replace_port_in_mapping_can_restore_unspecified_host():
|
||||
restored = _replace_port_in_mapping(
|
||||
"127.0.0.1:54001:5678",
|
||||
54001,
|
||||
9081,
|
||||
host_to=None,
|
||||
rewrite_host=True,
|
||||
)
|
||||
|
||||
assert restored == "9081:5678"
|
||||
Reference in New Issue
Block a user