Party Hardy

This commit is contained in:
2026-10-17 07:33:08 +02:00
parent d84e4cf3d3
commit 7274cc1840
51 changed files with 2738 additions and 2100 deletions
+36
View File
@@ -793,3 +793,39 @@ def test_tunnel_target_is_empty_without_a_route_to_the_port():
instance = {"ports_json": "[]", "container_gateway": "172.17.0.1"}
assert api.tunnel_target(instance, 3000) == (None, None)
assert api.tunnel_target({"container_ip": "172.17.0.9"}, 0) == (None, None)
def test_allocate_host_port_returns_lowest_free(monkeypatch):
monkeypatch.setattr(api, "_host_port_free", lambda port: True)
assert api.allocate_host_port(set()) == api.HOST_PORT_MIN
assert api.allocate_host_port({20001, 20002}) == 20003
def test_allocate_host_port_skips_bound_ports(monkeypatch):
monkeypatch.setattr(api, "_host_port_free", lambda port: port != 20001)
assert api.allocate_host_port(set()) == 20002
def test_allocate_host_port_probe_budget_exhausted(monkeypatch):
from devplacepy.services.containers.api import ContainerError
calls = []
monkeypatch.setattr(
api, "_host_port_free", lambda port: calls.append(port) or False
)
with pytest.raises(ContainerError, match="probing"):
api.allocate_host_port(set())
assert len(calls) == api.MAX_PORT_PROBES
def test_parse_ports_accepts_mapping_cap():
value = "\n".join(str(8000 + i) for i in range(api.MAX_PORTS_PER_INSTANCE))
assert len(api.parse_ports(value)) == api.MAX_PORTS_PER_INSTANCE
def test_parse_ports_rejects_too_many_mappings():
from devplacepy.services.containers.api import ContainerError
value = "\n".join(str(8000 + i) for i in range(api.MAX_PORTS_PER_INSTANCE + 1))
with pytest.raises(ContainerError, match="at most"):
api.parse_ports(value)