Skip to content

Commit 87304d0

Browse files
committed
Cover container naming for user-chosen and generated names
1 parent bbcc631 commit 87304d0

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

tests/test_coordinator.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ def test_container_name_uses_decoded_comment(self, hass):
10481048
coord = self._coord(hass)
10491049
with patch(
10501050
"custom_components.mikrotik_extended.coordinator.parse_api",
1051-
return_value={"veth1": {".id": "*1", "name": "uuid", "comment": self.RAW, "status": "running"}},
1051+
return_value={"veth1": {".id": "*1", "name": "4619db28-c827-4828-b4ac-ccf100192f97", "comment": self.RAW, "status": "running"}},
10521052
):
10531053
coord.get_containers()
10541054
assert coord.ds["containers"]["veth1"]["display-name"] == self.DECODED
@@ -1432,14 +1432,14 @@ def test_get_containers(self, hass):
14321432
containers = {
14331433
"veth1": {
14341434
".id": "*c1",
1435-
"name": "43915e42-uuid",
1435+
"name": "43915e42-8282-4617-a873-f4da221f529c",
14361436
"repo": "library/nginx:1.25",
14371437
"comment": "web",
14381438
"status": "running",
14391439
},
14401440
"veth2": {
14411441
".id": "*c2",
1442-
"name": "9a1b2c3d-uuid",
1442+
"name": "9a1b2c3d-1111-2222-3333-444455556666",
14431443
"repo": "library/redis:7",
14441444
"comment": "",
14451445
"status": "stopped",
@@ -1482,7 +1482,7 @@ def test_get_containers_legacy_tag_fallback(self, hass):
14821482
coord = _make_coordinator(hass)
14831483
coord.api.query.return_value = []
14841484
containers = {
1485-
"veth1": {".id": "*c1", "name": "uuid-1", "tag": "library/busybox:1.36", "status": "stopped"},
1485+
"veth1": {".id": "*c1", "name": "0af52d1e-9c5b-4f26-8d41-73a0b58c2ee1", "tag": "library/busybox:1.36", "status": "stopped"},
14861486
}
14871487
with patch(
14881488
"custom_components.mikrotik_extended.coordinator.parse_api",
@@ -1492,6 +1492,21 @@ def test_get_containers_legacy_tag_fallback(self, hass):
14921492

14931493
assert coord.ds["containers"]["veth1"]["display-name"] == "library/busybox:1.36"
14941494

1495+
def test_get_containers_user_named(self, hass):
1496+
"""A name the user chose wins over comment and image (issue 24)."""
1497+
coord = _make_coordinator(hass)
1498+
coord.api.query.return_value = []
1499+
containers = {
1500+
"veth1": {".id": "*c1", "name": "adguard", "tag": "adguard/adguardhome:v0.107", "comment": "dns", "status": "running"},
1501+
}
1502+
with patch(
1503+
"custom_components.mikrotik_extended.coordinator.parse_api",
1504+
return_value=containers,
1505+
):
1506+
coord.get_containers()
1507+
1508+
assert coord.ds["containers"]["veth1"]["display-name"] == "adguard"
1509+
14951510
def test_get_containers_uid_stable_across_recreate(self, hass):
14961511
"""A re-created container (new list id, same veth) keeps its uid."""
14971512
coord = _make_coordinator(hass)

0 commit comments

Comments
 (0)