Skip to content

Commit

Permalink
create lib
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Nov 28, 2023
1 parent ef84b63 commit f5a4aaf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""
import logging


from ops.charm import CharmBase, EventBase
from ops.framework import Object
from ops.model import WaitingStatus
Expand All @@ -22,14 +21,14 @@
CONFIG_SERVER_URI_KEY = "config-server-uri"

# The unique Charmhub library identifier, never change it
LIBID = "55fee8fa73364fb0a2dc16a954b2fd4a"
LIBID = "58ad1ccca4974932ba22b97781b9b2a0"

# Increment this major API version when introducing breaking changes
LIBAPI = 1
LIBAPI = 0

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 4
LIBPATCH = 1


class ClusterProvider(Object):
Expand Down
2 changes: 1 addition & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from charms.mongodb.v0.mongodb_secrets import SecretCache, generate_secret_label
from charms.mongodb.v0.mongodb_tls import MongoDBTLS
from charms.mongodb.v1.config_server_interface import ClusterProvider
from charms.mongodb.v0.config_server_interface import ClusterProvider
from charms.mongodb.v1.helpers import (
KEY_FILE,
TLS_EXT_CA_FILE,
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_config_server_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import unittest
from unittest.mock import patch

from ops.model import BlockedStatus, ModelError
from ops.testing import Harness

from charm import MongodbOperatorCharm
Expand All @@ -27,25 +26,26 @@ def setUp(self):
def test_on_relation_joined_failed_hook_checks(self, _update_relation_data):
"""Tests that no relation data is set when cluster joining conditions are not met."""

def is_role_mock_call(*args):
def is_not_config_mock_call(*args):
assert args == ("config-server",)
return False

self.harness.charm.app_peer_data["db_initialised"] = "True"

# fails due to being run on non-config-server
self.harness.charm.is_role = is_not_config_mock_call
relation_id = self.harness.add_relation("cluster", "mongos")
self.harness.add_relation_unit(relation_id, "mongos/0")
_update_relation_data.assert_not_called()

# fails because db has not been initialized
del self.harness.charm.app_peer_data["db_initialised"]

def is_role_mock_call(*args):
def is_config_mock_call(*args):
assert args == ("config-server",)
return True

self.harness.charm.is_role = is_role_mock_call
self.harness.charm.is_role = is_config_mock_call
self.harness.add_relation_unit(relation_id, "mongos/1")
_update_relation_data.assert_not_called()

Expand Down

0 comments on commit f5a4aaf

Please sign in to comment.