14
14
15
15
from typing import Optional
16
16
17
+ import google .cloud .alloydb_v1beta as v1beta
17
18
from mocks import FakeAlloyDBAdminAsyncClient
19
+ from mocks import FakeAlloyDBAdminClient
18
20
from mocks import FakeCredentials
19
21
import pytest
20
22
@@ -80,6 +82,40 @@ async def test__get_metadata_with_psc(credentials: FakeCredentials) -> None:
80
82
}
81
83
82
84
85
+ async def test__get_metadata_with_async_client (credentials : FakeCredentials ) -> None :
86
+ """
87
+ Test _get_metadata returns successfully for an async client.
88
+ """
89
+ test_client = AlloyDBClient ("" , "" , credentials , FakeAlloyDBAdminAsyncClient ())
90
+ test_client ._is_sync = False
91
+ assert (
92
+ await test_client ._get_metadata (
93
+ "test-project" ,
94
+ "test-region" ,
95
+ "test-cluster" ,
96
+ "psc-instance" ,
97
+ )
98
+ is not None
99
+ )
100
+
101
+
102
+ async def test__get_metadata_with_sync_client (credentials : FakeCredentials ) -> None :
103
+ """
104
+ Test _get_metadata returns successfully for a sync client.
105
+ """
106
+ test_client = AlloyDBClient ("" , "" , credentials , FakeAlloyDBAdminClient ())
107
+ test_client ._is_sync = True
108
+ assert (
109
+ await test_client ._get_metadata (
110
+ "test-project" ,
111
+ "test-region" ,
112
+ "test-cluster" ,
113
+ "psc-instance" ,
114
+ )
115
+ is not None
116
+ )
117
+
118
+
83
119
@pytest .mark .asyncio
84
120
async def test__get_client_certificate (credentials : FakeCredentials ) -> None :
85
121
"""
@@ -97,6 +133,40 @@ async def test__get_client_certificate(credentials: FakeCredentials) -> None:
97
133
assert cert_chain [2 ] == "This is the root cert"
98
134
99
135
136
+ async def test__get_client_certificate_with_async_client (
137
+ credentials : FakeCredentials ,
138
+ ) -> None :
139
+ """
140
+ Test _get_client_certificate returns successfully for an async client.
141
+ """
142
+ test_client = AlloyDBClient ("" , "" , credentials , FakeAlloyDBAdminAsyncClient ())
143
+ test_client ._is_sync = False
144
+ keys = await generate_keys ()
145
+ assert (
146
+ await test_client ._get_client_certificate (
147
+ "test-project" , "test-region" , "test-cluster" , keys [1 ]
148
+ )
149
+ is not None
150
+ )
151
+
152
+
153
+ async def test__get_client_certificate_with_sync_client (
154
+ credentials : FakeCredentials ,
155
+ ) -> None :
156
+ """
157
+ Test _get_client_certificate returns successfully for a sync client.
158
+ """
159
+ test_client = AlloyDBClient ("" , "" , credentials , FakeAlloyDBAdminClient ())
160
+ test_client ._is_sync = True
161
+ keys = await generate_keys ()
162
+ assert (
163
+ await test_client ._get_client_certificate (
164
+ "test-project" , "test-region" , "test-cluster" , keys [1 ]
165
+ )
166
+ is not None
167
+ )
168
+
169
+
100
170
@pytest .mark .asyncio
101
171
async def test_AlloyDBClient_init_ (credentials : FakeCredentials ) -> None :
102
172
"""
@@ -129,6 +199,48 @@ async def test_AlloyDBClient_init_custom_user_agent(
129
199
)
130
200
131
201
202
+ async def test_AlloyDBClient_init_specified_client (
203
+ credentials : FakeCredentials ,
204
+ ) -> None :
205
+ """
206
+ Test to check that __init__ method of AlloyDBClient uses specified client.
207
+ """
208
+ client = AlloyDBClient (
209
+ "www.test-endpoint.com" ,
210
+ "my-quota-project" ,
211
+ credentials ,
212
+ FakeAlloyDBAdminAsyncClient (),
213
+ )
214
+ assert client ._is_sync is False
215
+ assert type (client ._client ) is FakeAlloyDBAdminAsyncClient
216
+
217
+
218
+ async def test_AlloyDBClient_init_sync_client (credentials : FakeCredentials ) -> None :
219
+ """
220
+ Test to check that __init__ method of AlloyDBClient creates a sync client
221
+ when client is not specified and driver is pg8000.
222
+ """
223
+ client = AlloyDBClient (
224
+ "www.test-endpoint.com" , "my-quota-project" , credentials , driver = "pg8000"
225
+ )
226
+ assert client ._is_sync is True
227
+ assert type (client ._client ) is v1beta .AlloyDBAdminClient
228
+ assert client ._client .transport .kind == "grpc"
229
+
230
+
231
+ async def test_AlloyDBClient_init_async_client (credentials : FakeCredentials ) -> None :
232
+ """
233
+ Test to check that __init__ method of AlloyDBClient creates an async client
234
+ when client is not specified and driver is not pg8000.
235
+ """
236
+ client = AlloyDBClient (
237
+ "www.test-endpoint.com" , "my-quota-project" , credentials , driver = ""
238
+ )
239
+ assert client ._is_sync is False
240
+ assert type (client ._client ) is v1beta .AlloyDBAdminAsyncClient
241
+ assert client ._client .transport .kind == "grpc_asyncio"
242
+
243
+
132
244
@pytest .mark .parametrize (
133
245
"driver" ,
134
246
[None , "pg8000" , "asyncpg" ],
0 commit comments