Skip to content

Commit

Permalink
fmt and fix utests
Browse files Browse the repository at this point in the history
  • Loading branch information
IbraAoad committed Nov 27, 2024
1 parent 2b6ed32 commit ee0a5c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/charms/observability_libs/v1/kubernetes_service_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions tests/unit/test_kubernetes_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ee0a5c0

Please sign in to comment.