@@ -226,3 +226,80 @@ def test_list_instances(self):
226226 self .assertTrue (instance_2 ._client is client )
227227
228228 self .assertEqual (failed_locations , [FAILED_LOCATION ])
229+
230+ def test_list_clusters (self ):
231+ from google .cloud .bigtable_admin_v2 .gapic import (
232+ bigtable_instance_admin_client )
233+ from google .cloud .bigtable_admin_v2 .proto import (
234+ bigtable_instance_admin_pb2 as messages_v2_pb2 )
235+ from google .cloud .bigtable_admin_v2 .proto import (
236+ instance_pb2 as data_v2_pb2 )
237+ from google .cloud .bigtable .instance import Cluster
238+
239+ instance_api = (
240+ bigtable_instance_admin_client .BigtableInstanceAdminClient (
241+ mock .Mock ()))
242+ credentials = _make_credentials ()
243+ client = self ._make_one (project = self .PROJECT , credentials = credentials ,
244+ admin = True )
245+
246+ INSTANCE_ID1 = 'instance-id1'
247+ INSTANCE_ID2 = 'instance-id2'
248+
249+ failed_location = 'FAILED'
250+ cluster_id1 = '{}-cluster' .format (INSTANCE_ID1 )
251+ cluster_id2 = '{}-cluster-1' .format (INSTANCE_ID2 )
252+ cluster_id3 = '{}-cluster-2' .format (INSTANCE_ID2 )
253+ cluster_name1 = (client .instance_admin_client .cluster_path (
254+ self .PROJECT , INSTANCE_ID1 , cluster_id1 ))
255+ cluster_name2 = (client .instance_admin_client .cluster_path (
256+ self .PROJECT , INSTANCE_ID2 , cluster_id2 ))
257+ cluster_name3 = (client .instance_admin_client .cluster_path (
258+ self .PROJECT , INSTANCE_ID2 , cluster_id3 ))
259+
260+ # Create response_pb
261+ response_pb = messages_v2_pb2 .ListClustersResponse (
262+ failed_locations = [
263+ failed_location
264+ ],
265+ clusters = [
266+ data_v2_pb2 .Cluster (
267+ name = cluster_name1 ,
268+ ),
269+ data_v2_pb2 .Cluster (
270+ name = cluster_name2 ,
271+ ),
272+ data_v2_pb2 .Cluster (
273+ name = cluster_name3 ,
274+ ),
275+
276+ ],
277+ )
278+
279+ # Patch the stub used by the API method.
280+ client ._instance_admin_client = instance_api
281+ instance_stub = (
282+ client ._instance_admin_client .bigtable_instance_admin_stub )
283+ instance_stub .ListClusters .side_effect = [response_pb ]
284+
285+ # Perform the method and check the result.
286+ clusters , failed_locations = client .list_clusters ()
287+
288+ cluster_1 , cluster_2 , cluster_3 = clusters
289+
290+ self .assertIsInstance (cluster_1 , Cluster )
291+ self .assertEqual (cluster_1 .name , cluster_name1 )
292+ self .assertEqual (cluster_1 ._instance .instance_id ,
293+ INSTANCE_ID1 )
294+
295+ self .assertIsInstance (cluster_2 , Cluster )
296+ self .assertEqual (cluster_2 .name , cluster_name2 )
297+ self .assertEqual (cluster_2 ._instance .instance_id ,
298+ INSTANCE_ID2 )
299+
300+ self .assertIsInstance (cluster_3 , Cluster )
301+ self .assertEqual (cluster_3 .name , cluster_name3 )
302+ self .assertEqual (cluster_3 ._instance .instance_id ,
303+ INSTANCE_ID2 )
304+
305+ self .assertEqual (failed_locations , [failed_location ])
0 commit comments