@@ -106,6 +106,45 @@ def test_constructor_credentials_wo_create_scoped(self):
106106 expected_scopes = None
107107 self ._constructor_test_helper (expected_scopes , creds )
108108
109+ def test_admin_api_lib_name (self ):
110+ from google .cloud .spanner import __version__
111+ from google .cloud .gapic .spanner_admin_database import v1 as db
112+ from google .cloud .gapic .spanner_admin_instance import v1 as inst
113+
114+ # Get the actual admin client classes.
115+ DatabaseAdminClient = db .database_admin_client .DatabaseAdminClient
116+ InstanceAdminClient = inst .instance_admin_client .InstanceAdminClient
117+
118+ # Test that the DatabaseAdminClient is called with the gccl library
119+ # name and version.
120+ with mock .patch .object (DatabaseAdminClient , '__init__' ) as mock_dac :
121+ mock_dac .return_value = None
122+ client = self ._make_one (
123+ credentials = _make_credentials (),
124+ project = 'foo' ,
125+ )
126+ self .assertIsInstance (client .database_admin_api ,
127+ DatabaseAdminClient )
128+ mock_dac .assert_called_once ()
129+ self .assertEqual (mock_dac .mock_calls [0 ][2 ]['lib_name' ], 'gccl' )
130+ self .assertEqual (mock_dac .mock_calls [0 ][2 ]['lib_version' ],
131+ __version__ )
132+
133+ # Test that the InstanceAdminClient is called with the gccl library
134+ # name and version.
135+ with mock .patch .object (InstanceAdminClient , '__init__' ) as mock_iac :
136+ mock_iac .return_value = None
137+ client = self ._make_one (
138+ credentials = _make_credentials (),
139+ project = 'foo' ,
140+ )
141+ self .assertIsInstance (client .instance_admin_api ,
142+ InstanceAdminClient )
143+ mock_iac .assert_called_once ()
144+ self .assertEqual (mock_iac .mock_calls [0 ][2 ]['lib_name' ], 'gccl' )
145+ self .assertEqual (mock_iac .mock_calls [0 ][2 ]['lib_version' ],
146+ __version__ )
147+
109148 def test_instance_admin_api (self ):
110149 from google .cloud ._testing import _Monkey
111150 from google .cloud .spanner import client as MUT
@@ -114,14 +153,17 @@ def test_instance_admin_api(self):
114153 client = self ._make_one (project = self .PROJECT , credentials = creds )
115154
116155 class _Client (object ):
117- pass
156+ def __init__ (self , * args , ** kwargs ):
157+ self .args = args
158+ self .kwargs = kwargs
118159
119160 with _Monkey (MUT , InstanceAdminClient = _Client ):
120161 api = client .instance_admin_api
121162
122163 self .assertTrue (isinstance (api , _Client ))
123164 again = client .instance_admin_api
124165 self .assertTrue (again is api )
166+ self .assertEqual (api .kwargs ['lib_name' ], 'gccl' )
125167
126168 def test_database_admin_api (self ):
127169 from google .cloud ._testing import _Monkey
@@ -131,14 +173,17 @@ def test_database_admin_api(self):
131173 client = self ._make_one (project = self .PROJECT , credentials = creds )
132174
133175 class _Client (object ):
134- pass
176+ def __init__ (self , * args , ** kwargs ):
177+ self .args = args
178+ self .kwargs = kwargs
135179
136180 with _Monkey (MUT , DatabaseAdminClient = _Client ):
137181 api = client .database_admin_api
138182
139183 self .assertTrue (isinstance (api , _Client ))
140184 again = client .database_admin_api
141185 self .assertTrue (again is api )
186+ self .assertEqual (api .kwargs ['lib_name' ], 'gccl' )
142187
143188 def test_copy (self ):
144189 credentials = _Credentials ('value' )
0 commit comments