mirror of
https://github.com/Red5d/docker-autocompose
synced 2026-07-04 00:28:24 +00:00
Add regression coverage for network aliases and healthcheck output
This commit is contained in:
committed by
GitHub
parent
d213724bde
commit
4479f0674f
+4
-3
@@ -36,15 +36,16 @@ def build_service_networks(network_settings, default_networks):
|
|||||||
if not custom_networks:
|
if not custom_networks:
|
||||||
return None, set()
|
return None, set()
|
||||||
|
|
||||||
if any(custom_networks.values()):
|
has_network_config = any(network_values for network_values in custom_networks.values())
|
||||||
return {name: values if values else {} for name, values in custom_networks.items()}, set(custom_networks.keys())
|
if has_network_config:
|
||||||
|
return custom_networks, set(custom_networks.keys())
|
||||||
|
|
||||||
return sorted(custom_networks.keys()), set(custom_networks.keys())
|
return sorted(custom_networks.keys()), set(custom_networks.keys())
|
||||||
|
|
||||||
|
|
||||||
def build_healthcheck(config):
|
def build_healthcheck(config):
|
||||||
healthcheck = config.get("Healthcheck")
|
healthcheck = config.get("Healthcheck")
|
||||||
if healthcheck in IGNORE_VALUES:
|
if not isinstance(healthcheck, dict):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
values = {}
|
values = {}
|
||||||
|
|||||||
+24
-16
@@ -5,9 +5,8 @@ from src import autocompose
|
|||||||
|
|
||||||
|
|
||||||
class FakeContainerSummary:
|
class FakeContainerSummary:
|
||||||
def __init__(self, name, short_id):
|
name = "svc"
|
||||||
self.name = name
|
short_id = "abc123"
|
||||||
self.short_id = short_id
|
|
||||||
|
|
||||||
|
|
||||||
class FakeContainerWithAttrs:
|
class FakeContainerWithAttrs:
|
||||||
@@ -16,11 +15,11 @@ class FakeContainerWithAttrs:
|
|||||||
|
|
||||||
|
|
||||||
class FakeContainers:
|
class FakeContainers:
|
||||||
def __init__(self, attrs, name="svc", short_id="abc123"):
|
def __init__(self, attrs):
|
||||||
self._attrs = attrs
|
self._attrs = attrs
|
||||||
self._summary = FakeContainerSummary(name=name, short_id=short_id)
|
self._summary = FakeContainerSummary()
|
||||||
|
|
||||||
def list(self, all=True):
|
def list(self, **_kwargs):
|
||||||
return [self._summary]
|
return [self._summary]
|
||||||
|
|
||||||
def get(self, _cid):
|
def get(self, _cid):
|
||||||
@@ -89,13 +88,28 @@ def make_attrs(networks, healthcheck=None):
|
|||||||
|
|
||||||
|
|
||||||
class GenerateTests(unittest.TestCase):
|
class GenerateTests(unittest.TestCase):
|
||||||
def test_preserves_network_aliases_and_healthcheck(self):
|
def test_preserves_network_aliases(self):
|
||||||
attrs = make_attrs(
|
attrs = make_attrs(
|
||||||
{
|
{
|
||||||
"custom_net": {
|
"custom_net": {
|
||||||
"Aliases": ["svc", "db"],
|
"Aliases": ["svc", "db"],
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
)
|
||||||
|
fake_client = FakeDockerClient(attrs, networks=[("custom_net", False)])
|
||||||
|
|
||||||
|
with patch("src.autocompose.docker.from_env", return_value=fake_client):
|
||||||
|
cfile, c_networks, _ = autocompose.generate("svc")
|
||||||
|
|
||||||
|
self.assertEqual(cfile["svc"]["networks"], {"custom_net": {"aliases": ["svc", "db"]}})
|
||||||
|
self.assertEqual(
|
||||||
|
c_networks,
|
||||||
|
{"custom_net": {"external": True, "name": "custom_net"}},
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_serializes_healthcheck_config(self):
|
||||||
|
attrs = make_attrs(
|
||||||
|
{"custom_net": {}},
|
||||||
healthcheck={
|
healthcheck={
|
||||||
"Test": ["CMD-SHELL", "echo ok"],
|
"Test": ["CMD-SHELL", "echo ok"],
|
||||||
"Interval": 1000000000,
|
"Interval": 1000000000,
|
||||||
@@ -107,12 +121,10 @@ class GenerateTests(unittest.TestCase):
|
|||||||
fake_client = FakeDockerClient(attrs, networks=[("custom_net", False)])
|
fake_client = FakeDockerClient(attrs, networks=[("custom_net", False)])
|
||||||
|
|
||||||
with patch("src.autocompose.docker.from_env", return_value=fake_client):
|
with patch("src.autocompose.docker.from_env", return_value=fake_client):
|
||||||
cfile, c_networks, _ = autocompose.generate("svc")
|
cfile, _, _ = autocompose.generate("svc")
|
||||||
|
|
||||||
service = cfile["svc"]
|
|
||||||
self.assertEqual(service["networks"], {"custom_net": {"aliases": ["svc", "db"]}})
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
service["healthcheck"],
|
cfile["svc"]["healthcheck"],
|
||||||
{
|
{
|
||||||
"test": ["CMD-SHELL", "echo ok"],
|
"test": ["CMD-SHELL", "echo ok"],
|
||||||
"interval": "1000000000ns",
|
"interval": "1000000000ns",
|
||||||
@@ -121,10 +133,6 @@ class GenerateTests(unittest.TestCase):
|
|||||||
"start_period": "3000000000ns",
|
"start_period": "3000000000ns",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
|
||||||
c_networks,
|
|
||||||
{"custom_net": {"external": True, "name": "custom_net"}},
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_simple_custom_network_uses_list_form(self):
|
def test_simple_custom_network_uses_list_form(self):
|
||||||
attrs = make_attrs({"custom_net": {}})
|
attrs = make_attrs({"custom_net": {}})
|
||||||
|
|||||||
Reference in New Issue
Block a user