10
10
11
11
from charm import CassandraCharm
12
12
from core .state import PEER_RELATION
13
+ from managers .config import ConfigManager
13
14
14
15
BOOTSTRAP_RELATION = "bootstrap"
16
+ PEER_SECRET = "cassandra-peers.cassandra.app"
17
+
18
+ # TODO: add start change password unit test
15
19
16
20
17
21
def test_start_leader ():
18
22
"""Leader should render all required configs and start workload."""
19
23
ctx = testing .Context (CassandraCharm )
20
24
relation = testing .PeerRelation (id = 1 , endpoint = PEER_RELATION )
21
25
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 })
23
28
24
29
with (
25
30
patch ("managers.config.ConfigManager.render_env" ) as render_env ,
@@ -57,7 +62,8 @@ def test_start_subordinate_only_after_leader_active():
57
62
relation = testing .PeerRelation (
58
63
id = 1 , endpoint = PEER_RELATION , local_app_data = {"cluster_state" : "active" }
59
64
)
60
- state = testing .State (leader = False , relations = {relation })
65
+ secret = testing .Secret (label = PEER_SECRET , tracked_content = {"cassandra-password" : "ua" })
66
+ state = testing .State (leader = False , relations = {relation }, secrets = {secret })
61
67
62
68
state = ctx .run (ctx .on .start (), state )
63
69
bootstrap .assert_called_once ()
@@ -109,14 +115,16 @@ def test_config_changed():
109
115
state = testing .State (leader = True , relations = {relation , bootstrap_relation })
110
116
with (
111
117
patch ("managers.config.ConfigManager.render_env" ) as render_env ,
118
+ patch ("managers.config.ConfigManager.render_cassandra_config" ) as render_cassandra_config ,
112
119
patch ("charm.CassandraWorkload" ) as workload ,
113
120
patch (
114
121
"managers.cluster.ClusterManager.is_healthy" ,
115
122
new_callable = PropertyMock (return_value = True ),
116
123
),
117
124
):
118
125
state = ctx .run (ctx .on .config_changed (), state )
119
- render_env .assert_called ()
126
+ render_env .assert_not_called ()
127
+ render_cassandra_config .assert_not_called ()
120
128
workload .return_value .restart .assert_not_called ()
121
129
122
130
relation = testing .PeerRelation (
@@ -127,4 +135,5 @@ def test_config_changed():
127
135
render_env .reset_mock ()
128
136
state = ctx .run (ctx .on .config_changed (), state )
129
137
render_env .assert_called ()
138
+ render_cassandra_config .assert_called ()
130
139
workload .return_value .restart .assert_called_once ()
0 commit comments