Skip to content

Commit e9cd929

Browse files
chore: fix existing tests
1 parent 7cf7273 commit e9cd929

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from unit.mocks import FakeCSQLInstance # type: ignore
2727

2828
from google.cloud.sql.connector.client import CloudSQLClient
29+
from google.cloud.sql.connector.connection_name import ConnectionName
2930
from google.cloud.sql.connector.instance import RefreshAheadCache
3031
from google.cloud.sql.connector.utils import generate_keys
3132

@@ -144,7 +145,7 @@ async def fake_client(
144145
async def cache(fake_client: CloudSQLClient) -> AsyncGenerator[RefreshAheadCache, None]:
145146
keys = asyncio.create_task(generate_keys())
146147
cache = RefreshAheadCache(
147-
"test-project:test-region:test-instance",
148+
ConnectionName("test-project", "test-region", "test-instance"),
148149
client=fake_client,
149150
keys=keys,
150151
)

tests/unit/test_connector.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from google.cloud.sql.connector import create_async_connector
2727
from google.cloud.sql.connector import IPTypes
2828
from google.cloud.sql.connector.client import CloudSQLClient
29+
from google.cloud.sql.connector.connection_name import ConnectionName
2930
from google.cloud.sql.connector.exceptions import CloudSQLIPTypeError
3031
from google.cloud.sql.connector.exceptions import IncompatibleDriverError
3132
from google.cloud.sql.connector.instance import RefreshAheadCache
@@ -322,18 +323,18 @@ async def test_Connector_remove_cached_bad_instance(
322323
async with Connector(
323324
credentials=fake_credentials, loop=asyncio.get_running_loop()
324325
) as connector:
325-
conn_name = "bad-project:bad-region:bad-inst"
326+
conn_name = ConnectionName("bad-project", "bad-region", "bad-inst")
326327
# populate cache
327328
cache = RefreshAheadCache(conn_name, fake_client, connector._keys)
328-
connector._cache[(conn_name, False)] = cache
329+
connector._cache[(str(conn_name), False)] = cache
329330
# aiohttp client should throw a 404 ClientResponseError
330331
with pytest.raises(ClientResponseError):
331332
await connector.connect_async(
332-
conn_name,
333+
str(conn_name),
333334
"pg8000",
334335
)
335336
# check that cache has been removed from dict
336-
assert (conn_name, False) not in connector._cache
337+
assert (str(conn_name), False) not in connector._cache
337338

338339

339340
async def test_Connector_remove_cached_no_ip_type(
@@ -348,21 +349,21 @@ async def test_Connector_remove_cached_no_ip_type(
348349
async with Connector(
349350
credentials=fake_credentials, loop=asyncio.get_running_loop()
350351
) as connector:
351-
conn_name = "test-project:test-region:test-instance"
352+
conn_name = ConnectionName("test-project", "test-region", "test-instance")
352353
# populate cache
353354
cache = RefreshAheadCache(conn_name, fake_client, connector._keys)
354-
connector._cache[(conn_name, False)] = cache
355+
connector._cache[(str(conn_name), False)] = cache
355356
# test instance does not have Private IP, thus should invalidate cache
356357
with pytest.raises(CloudSQLIPTypeError):
357358
await connector.connect_async(
358-
conn_name,
359+
str(conn_name),
359360
"pg8000",
360361
user="my-user",
361362
password="my-pass",
362363
ip_type="private",
363364
)
364365
# check that cache has been removed from dict
365-
assert (conn_name, False) not in connector._cache
366+
assert (str(conn_name), False) not in connector._cache
366367

367368

368369
def test_default_universe_domain(fake_credentials: Credentials) -> None:

tests/unit/test_instance.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from google.cloud.sql.connector import IPTypes
2929
from google.cloud.sql.connector.client import CloudSQLClient
3030
from google.cloud.sql.connector.connection_info import ConnectionInfo
31+
from google.cloud.sql.connector.connection_name import ConnectionName
3132
from google.cloud.sql.connector.exceptions import AutoIAMAuthNotSupported
3233
from google.cloud.sql.connector.exceptions import CloudSQLIPTypeError
3334
from google.cloud.sql.connector.instance import RefreshAheadCache
@@ -300,7 +301,7 @@ async def test_ClientResponseError(
300301
repeat=True,
301302
)
302303
cache = RefreshAheadCache(
303-
"my-project:my-region:my-instance",
304+
ConnectionName("my-project", "my-region", "my-instance"),
304305
client,
305306
keys,
306307
)
@@ -328,7 +329,7 @@ async def test_AutoIAMAuthNotSupportedError(fake_client: CloudSQLClient) -> None
328329
# generate client key pair
329330
keys = asyncio.create_task(generate_keys())
330331
cache = RefreshAheadCache(
331-
"test-project:test-region:sqlserver-instance",
332+
ConnectionName("test-project", "test-region", "sqlserver-instance"),
332333
client=fake_client,
333334
keys=keys,
334335
enable_iam_auth=True,

tests/unit/test_lazy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from google.cloud.sql.connector.client import CloudSQLClient
1818
from google.cloud.sql.connector.connection_info import ConnectionInfo
19+
from google.cloud.sql.connector.connection_name import ConnectionName
1920
from google.cloud.sql.connector.lazy import LazyRefreshCache
2021
from google.cloud.sql.connector.utils import generate_keys
2122

@@ -26,7 +27,7 @@ async def test_LazyRefreshCache_connect_info(fake_client: CloudSQLClient) -> Non
2627
"""
2728
keys = asyncio.create_task(generate_keys())
2829
cache = LazyRefreshCache(
29-
"test-project:test-region:test-instance",
30+
ConnectionName("test-project", "test-region", "test-instance"),
3031
client=fake_client,
3132
keys=keys,
3233
enable_iam_auth=False,
@@ -47,7 +48,7 @@ async def test_LazyRefreshCache_force_refresh(fake_client: CloudSQLClient) -> No
4748
"""
4849
keys = asyncio.create_task(generate_keys())
4950
cache = LazyRefreshCache(
50-
"test-project:test-region:test-instance",
51+
ConnectionName("test-project", "test-region", "test-instance"),
5152
client=fake_client,
5253
keys=keys,
5354
enable_iam_auth=False,

0 commit comments

Comments
 (0)