Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Feb 19, 2024
1 parent 0670225 commit a00e314
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from charms.data_platform_libs.v0.data_interfaces import DatabaseRequiresEvents

CLUSTER_ALIAS = "cluster"
MONGOS_SOCKET_URI_FMT = "%2Fvar%2Fsnap%2Fcharmed-mongodb%2Fcommon%2Fvar%2Fmongodb-27018.sock"


class TestCharm(unittest.TestCase):
Expand All @@ -32,9 +33,7 @@ def setUp(self, *unused):
# related to duplicated events.
delattr(DatabaseRequiresEvents, f"{CLUSTER_ALIAS}_database_created")
delattr(DatabaseRequiresEvents, f"{CLUSTER_ALIAS}_endpoints_changed")
delattr(
DatabaseRequiresEvents, f"{CLUSTER_ALIAS}_read_only_endpoints_changed"
)
delattr(DatabaseRequiresEvents, f"{CLUSTER_ALIAS}_read_only_endpoints_changed")
except AttributeError:
# Ignore the events not existing before the first test.
pass
Expand Down Expand Up @@ -143,3 +142,14 @@ def test_status_shows_mongos_waiting(self):
self.harness.add_relation("cluster", "config-server")
self.harness.charm.on.update_status.emit()
self.assertTrue(isinstance(self.harness.charm.unit.status, WaitingStatus))

@patch_network_get(private_address="1.1.1.1")
def test_mongos_host(self):
"""TBD."""
self.harness.charm.app_peer_data["external-connectivity"] = json.dumps(False)
mongos_host = self.harness.charm.get_mongos_host()
self.assertEqual(mongos_host, MONGOS_SOCKET_URI_FMT)

self.harness.charm.app_peer_data["external-connectivity"] = json.dumps(True)
mongos_host = self.harness.charm.get_mongos_host()
self.assertEqual(mongos_host, "1.1.1.1")

0 comments on commit a00e314

Please sign in to comment.