@@ -231,6 +231,71 @@ def test_reload(self):
231231 self .assertEqual (cluster .serve_nodes , serve_nodes )
232232 self .assertEqual (cluster .display_name , display_name )
233233
234+ def test_operation_finished_without_operation (self ):
235+ zone = 'zone'
236+ cluster_id = 'cluster-id'
237+ cluster = self ._makeOne (zone , cluster_id , None )
238+ self .assertEqual (cluster ._operation_type , None )
239+ with self .assertRaises (ValueError ):
240+ cluster .operation_finished ()
241+
242+ def _operation_finished_helper (self , done ):
243+ from gcloud .bigtable ._generated import operations_pb2
244+ from gcloud .bigtable ._testing import _FakeStub
245+
246+ project = 'PROJECT'
247+ zone = 'zone'
248+ cluster_id = 'cluster-id'
249+ timeout_seconds = 1
250+
251+ client = _Client (project , timeout_seconds = timeout_seconds )
252+ cluster = self ._makeOne (zone , cluster_id , client )
253+
254+ # Patch up the cluster's operation attributes.
255+ cluster ._operation_id = op_id = 789
256+ cluster ._operation_begin = op_begin = object ()
257+ cluster ._operation_type = op_type = object ()
258+
259+ # Create request_pb
260+ op_name = ('operations/projects/' + project + '/zones/' +
261+ zone + '/clusters/' + cluster_id +
262+ '/operations/%d' % (op_id ,))
263+ request_pb = operations_pb2 .GetOperationRequest (name = op_name )
264+
265+ # Create response_pb
266+ response_pb = operations_pb2 .Operation (done = done )
267+
268+ # Patch the stub used by the API method.
269+ client ._operations_stub = stub = _FakeStub (response_pb )
270+
271+ # Create expected_result.
272+ expected_result = done
273+
274+ # Perform the method and check the result.
275+ result = cluster .operation_finished ()
276+
277+ self .assertEqual (result , expected_result )
278+ self .assertEqual (stub .method_calls , [(
279+ 'GetOperation' ,
280+ (request_pb , timeout_seconds ),
281+ {},
282+ )])
283+
284+ if done :
285+ self .assertEqual (cluster ._operation_type , None )
286+ self .assertEqual (cluster ._operation_id , None )
287+ self .assertEqual (cluster ._operation_begin , None )
288+ else :
289+ self .assertEqual (cluster ._operation_type , op_type )
290+ self .assertEqual (cluster ._operation_id , op_id )
291+ self .assertEqual (cluster ._operation_begin , op_begin )
292+
293+ def test_operation_finished (self ):
294+ self ._operation_finished_helper (done = True )
295+
296+ def test_operation_finished_not_done (self ):
297+ self ._operation_finished_helper (done = False )
298+
234299 def test_create (self ):
235300 from gcloud ._testing import _Monkey
236301 from gcloud .bigtable ._generated import (
0 commit comments