From ee0a5c0300bf6258dd136562859fe59b81b6b2bd Mon Sep 17 00:00:00 2001 From: IbraAoad Date: Wed, 27 Nov 2024 15:39:44 +0200 Subject: [PATCH] fmt and fix utests --- .../v1/kubernetes_service_patch.py | 8 ++++++-- tests/unit/test_kubernetes_service.py | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/charms/observability_libs/v1/kubernetes_service_patch.py b/lib/charms/observability_libs/v1/kubernetes_service_patch.py index 2ba47c5..9774737 100644 --- a/lib/charms/observability_libs/v1/kubernetes_service_patch.py +++ b/lib/charms/observability_libs/v1/kubernetes_service_patch.py @@ -367,8 +367,12 @@ def _is_patched(self, client: Client) -> bool: ports_match = expected_ports == fetched_ports # Construct expected and fetched annotations - expected_annotations = self.service.metadata.annotations or {} # pyright: ignore[reportOptionalMemberAccess] - fetched_annotations = service.metadata.annotations or {} # pyright: ignore[reportOptionalMemberAccess] + expected_annotations = ( + self.service.metadata.annotations or {} # pyright: ignore[reportOptionalMemberAccess] + ) + fetched_annotations = ( + service.metadata.annotations or {} # pyright: ignore[reportOptionalMemberAccess] + ) # Validate annotations annotations_match = expected_annotations == fetched_annotations diff --git a/tests/unit/test_kubernetes_service.py b/tests/unit/test_kubernetes_service.py index 1ce8ee4..984e58e 100644 --- a/tests/unit/test_kubernetes_service.py +++ b/tests/unit/test_kubernetes_service.py @@ -397,14 +397,22 @@ def test_patch_k8s_service(self, client_patch): # Patch should work even on a non-leader unit # Check we call the patch method on the client with the correct arguments client_patch.assert_called_with( - Service, "test-charm", charm.service_patch.service, patch_type=PatchType.MERGE + Service, + "test-charm", + charm.service_patch.service, + patch_type=PatchType.APPLY, + field_manager=charm.app.name, ) self.harness.set_leader(True) charm.on.install.emit() # Check we call the patch method on the client with the correct arguments client_patch.assert_called_with( - Service, "test-charm", charm.service_patch.service, patch_type=PatchType.MERGE + Service, + "test-charm", + charm.service_patch.service, + patch_type=PatchType.APPLY, + field_manager=charm.app.name, ) client_patch.side_effect = _FakeApiError(403)