@@ -149,6 +149,28 @@ def test_restore_state(self):
149
149
self .instances .restore_state .return_value )
150
150
self .service .enable .assert_called_with ()
151
151
152
+ def test_update_node_pool_enabled (self ):
153
+ autospec_method (self .service .repair )
154
+ self .service .enabled = True
155
+ node_pool = mock .Mock ()
156
+
157
+ self .service .update_node_pool (node_pool )
158
+
159
+ self .service .instances .update_node_pool .assert_called_once_with (node_pool )
160
+ self .service .instances .clear_extra .assert_called_once_with ()
161
+ self .service .repair .assert_called_once_with ()
162
+
163
+ def test_update_node_pool_disabled (self ):
164
+ autospec_method (self .service .repair )
165
+ self .service .enabled = False
166
+ node_pool = mock .Mock ()
167
+
168
+ self .service .update_node_pool (node_pool )
169
+
170
+ self .service .instances .update_node_pool .assert_called_once_with (node_pool )
171
+ self .service .instances .clear_extra .assert_called_once_with ()
172
+ assert not self .service .repair .called
173
+
152
174
153
175
class ServiceCollectionTestCase (TestCase ):
154
176
@@ -162,25 +184,64 @@ def _add_service(self):
162
184
self .collection .services .update (
163
185
(serv .name , serv ) for serv in self .service_list )
164
186
187
+ def test_build_with_new_config (self ):
188
+ new_config = mock .Mock (
189
+ name = 'i_come_from_the_land_of_ice_and_snow' ,
190
+ count = 42 )
191
+ new_service = mock .Mock (config = new_config )
192
+ old_service = mock .Mock ()
193
+ with mock .patch .object (self .collection , 'get_by_name' , return_value = old_service ) \
194
+ as get_patch :
195
+ assert not self .collection ._build (new_service )
196
+ assert not old_service .update_node_pool .called
197
+ get_patch .assert_called_once_with (new_config .name )
198
+
199
+ def test_build_with_same_config (self ):
200
+ config = mock .Mock (
201
+ name = 'hamsteak' ,
202
+ count = 413 )
203
+ old_service = mock .Mock (config = config )
204
+ new_service = mock .Mock (config = config )
205
+ with mock .patch .object (self .collection , 'get_by_name' , return_value = old_service ) \
206
+ as get_patch :
207
+ assert self .collection ._build (new_service )
208
+ get_patch .assert_called_once_with (config .name )
209
+ old_service .update_node_pool .assert_called_once_with (new_service .instances .node_pool )
210
+ assert_equal (old_service .instances .context , new_service .instances .context )
211
+
212
+ def test_build_with_diff_count (self ):
213
+ name = 'ni'
214
+ old_config = mock .Mock (
215
+ count = 77 )
216
+ new_config = mock .Mock (
217
+ count = 1111111111111 )
218
+ new_eq = lambda s , o : (s .name == o .name and s .count == o .count )
219
+ old_config .__eq__ = new_eq
220
+ new_config .__eq__ = new_eq
221
+ # We have to do this, since name is an actual kwarg for mock.Mock().
222
+ old_config .name = name
223
+ new_config .name = name
224
+ old_service = mock .Mock (config = old_config )
225
+ new_service = mock .Mock (config = new_config )
226
+ with mock .patch .object (self .collection , 'get_by_name' , return_value = old_service ) \
227
+ as get_patch :
228
+ assert self .collection ._build (new_service )
229
+ get_patch .assert_called_once_with (new_service .config .name )
230
+ old_service .update_node_pool .assert_called_once_with (new_service .instances .node_pool )
231
+ assert_equal (old_service .instances .context , new_service .instances .context )
232
+
165
233
@mock .patch ('tron.core.service.Service' , autospec = True )
166
234
def test_load_from_config (self , mock_service ):
167
235
autospec_method (self .collection .get_names )
168
- autospec_method (self .collection .add )
236
+ autospec_method (self .collection .services . add )
169
237
service_configs = {'a' : mock .Mock (), 'b' : mock .Mock ()}
170
238
context = mock .create_autospec (command_context .CommandContext )
171
239
result = list (self .collection .load_from_config (service_configs , context ))
172
240
expected = [mock .call (config , context )
173
241
for config in service_configs .itervalues ()]
174
242
assert_mock_calls (expected , mock_service .from_config .mock_calls )
175
- expected = [mock .call (s ) for s in result ]
176
- assert_mock_calls (expected , self .collection .add .mock_calls )
177
-
178
- def test_add (self ):
179
- self .collection .services = mock .MagicMock ()
180
- service = mock .Mock ()
181
- result = self .collection .add (service )
182
- self .collection .services .replace .assert_called_with (service )
183
- assert_equal (result , self .collection .services .replace .return_value )
243
+ expected = [mock .call (s , self .collection ._build ) for s in result ]
244
+ assert_mock_calls (expected , self .collection .services .add .mock_calls )
184
245
185
246
def test_restore_state (self ):
186
247
state_count = 2
0 commit comments