mirror of
https://github.com/katanemo/plano.git
synced 2026-05-03 21:02:56 +02:00
Merge 1c245ee19c into b81eb7266c
This commit is contained in:
commit
3d7a977089
2 changed files with 78 additions and 1 deletions
46
cli/test/test_docker_cli.py
Normal file
46
cli/test/test_docker_cli.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import subprocess
|
||||
from unittest import mock
|
||||
|
||||
from planoai.docker_cli import _get_host_ip
|
||||
|
||||
|
||||
def test_get_host_ip_returns_bridge_gateway():
|
||||
"""When docker network inspect succeeds, the bridge gateway IP is returned."""
|
||||
fake_result = mock.Mock()
|
||||
fake_result.returncode = 0
|
||||
fake_result.stdout = "172.17.0.1\n"
|
||||
|
||||
with mock.patch("subprocess.run", return_value=fake_result) as mock_run:
|
||||
ip = _get_host_ip()
|
||||
|
||||
assert ip == "172.17.0.1"
|
||||
mock_run.assert_called_once()
|
||||
args = mock_run.call_args[0][0]
|
||||
assert "docker" in args
|
||||
assert "network" in args
|
||||
assert "inspect" in args
|
||||
assert "bridge" in args
|
||||
|
||||
|
||||
def test_get_host_ip_falls_back_on_failure():
|
||||
"""When docker network inspect fails, 'host-gateway' is returned as a fallback."""
|
||||
fake_result = mock.Mock()
|
||||
fake_result.returncode = 1
|
||||
fake_result.stdout = ""
|
||||
|
||||
with mock.patch("subprocess.run", return_value=fake_result):
|
||||
ip = _get_host_ip()
|
||||
|
||||
assert ip == "host-gateway"
|
||||
|
||||
|
||||
def test_get_host_ip_falls_back_on_empty_output():
|
||||
"""When docker network inspect returns empty output, 'host-gateway' is returned."""
|
||||
fake_result = mock.Mock()
|
||||
fake_result.returncode = 0
|
||||
fake_result.stdout = " "
|
||||
|
||||
with mock.patch("subprocess.run", return_value=fake_result):
|
||||
ip = _get_host_ip()
|
||||
|
||||
assert ip == "host-gateway"
|
||||
Loading…
Add table
Add a link
Reference in a new issue