Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IbraAoad committed Jul 9, 2024
1 parent d3ea056 commit 7c0d4fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/charms/observability_libs/v1/kubernetes_service_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ def setUp(self, *unused):

import logging
from types import MethodType
from typing import List, Literal, Optional, Union
from typing import Any, List, Literal, Optional, Union

from lightkube import ApiError, Client # pyright: ignore
from lightkube.core import exceptions
from lightkube.models.core_v1 import ServicePort, ServiceSpec
from lightkube.models.meta_v1 import LabelSelector, ObjectMeta
from lightkube.models.meta_v1 import ObjectMeta
from lightkube.resources.core_v1 import Service
from lightkube.types import PatchType
from ops import UpgradeCharmEvent
Expand Down Expand Up @@ -365,10 +365,10 @@ def _on_upgrade_charm(self, event: UpgradeCharmEvent):
client = Client() # pyright: ignore

# Define a label selector to find services related to the app
selector = LabelSelector(matchLabels={"app.kubernetes.io/name": self._app})
selector: dict[str, Any] = {"app.kubernetes.io/name": self._app}

# Check if any service of type LoadBalancer exists
services = client.list(Service, namespace=self._namespace, labels=selector.to_dict())
services = client.list(Service, namespace=self._namespace, labels=selector)
for service in services:
if (
not service.metadata
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_kubernetes_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def test_given_initialized_charm_when_install_event_then_event_listener_is_attac
charm.on.install.emit()
self.assertEqual(patch.call_count, 1)

@patch(f"{CL_PATH}._namespace", "test")
def test_given_initialized_charm_when_upgrade_event_then_event_listener_is_attached(self):
charm = self.harness.charm
with mock.patch(f"{CL_PATH}._patch") as patch:
Expand Down

0 comments on commit 7c0d4fe

Please sign in to comment.