Skip to content

Commit d326251

Browse files
committed
Fix unit tests.
1 parent f71876c commit d326251

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

tests/unit/test_charm.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@
1010

1111
from charm import CassandraCharm
1212
from core.state import PEER_RELATION
13+
from managers.config import ConfigManager
1314

1415
BOOTSTRAP_RELATION = "bootstrap"
16+
PEER_SECRET = "cassandra-peers.cassandra.app"
17+
18+
# TODO: add start change password unit test
1519

1620

1721
def test_start_leader():
1822
"""Leader should render all required configs and start workload."""
1923
ctx = testing.Context(CassandraCharm)
2024
relation = testing.PeerRelation(id=1, endpoint=PEER_RELATION)
2125
bootstrap_relation = testing.PeerRelation(id=2, endpoint=BOOTSTRAP_RELATION)
22-
state = testing.State(leader=True, relations={relation, bootstrap_relation})
26+
secret = testing.Secret(label=PEER_SECRET, tracked_content={"cassandra-password": "ua"})
27+
state = testing.State(leader=True, relations={relation, bootstrap_relation}, secrets={secret})
2328

2429
with (
2530
patch("managers.config.ConfigManager.render_env") as render_env,
@@ -78,7 +83,8 @@ def test_start_subordinate_only_after_leader_active():
7883
relation = testing.PeerRelation(
7984
id=1, endpoint=PEER_RELATION, local_app_data={"cluster_state": "active"}
8085
)
81-
state = testing.State(leader=False, relations={relation})
86+
secret = testing.Secret(label=PEER_SECRET, tracked_content={"cassandra-password": "ua"})
87+
state = testing.State(leader=False, relations={relation}, secrets={secret})
8288

8389
state = ctx.run(ctx.on.start(), state)
8490
bootstrap.assert_called_once()
@@ -165,8 +171,8 @@ def test_config_changed():
165171
),
166172
):
167173
state = ctx.run(ctx.on.config_changed(), state)
168-
render_env.assert_called()
169-
render_cassandra_config.assert_called()
174+
render_env.assert_not_called()
175+
render_cassandra_config.assert_not_called()
170176
workload.return_value.restart.assert_not_called()
171177

172178
relation = testing.PeerRelation(

tests/unit/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def test_render_env_preserves_existing_vars():
2121
enable_client_tls=False,
2222
keystore_password="",
2323
truststore_password="",
24+
authentication=False,
2425
)
2526

2627
workload.cassandra_paths.env.read_text.return_value = (

0 commit comments

Comments
 (0)