@@ -2175,39 +2175,49 @@ async def test_get_control_plane_client_quota_project_id(
21752175
21762176@pytest .mark .asyncio
21772177@pytest .mark .parametrize (
2178- "endpoint_url, env_updates, expected_host" ,
2178+ "endpoint_url, env_updates, expected_host, expected_insecure " ,
21792179 [
2180- ("https://my-endpoint.com" , {}, "my-endpoint.com" ),
2180+ ("https://my-endpoint.com" , {}, "my-endpoint.com" , False ),
21812181 (
21822182 None ,
21832183 {
21842184 "GOOGLE_CLOUD_UNIVERSE_DOMAIN" : "apis-tpczero.goog" ,
21852185 "STORAGE_EMULATOR_HOST" : "" ,
21862186 },
21872187 "storage.apis-tpczero.goog" ,
2188+ False ,
21882189 ),
21892190 (
21902191 None ,
21912192 {
21922193 "GOOGLE_CLOUD_UNIVERSE_DOMAIN" : "apis-tpczero.goog" ,
2193- "STORAGE_EMULATOR_HOST" : "my-emulator.com" ,
2194+ "STORAGE_EMULATOR_HOST" : "http:// my-emulator.com" ,
21942195 },
21952196 "my-emulator.com" ,
2197+ True ,
21962198 ),
2197- (None , {"STORAGE_EMULATOR_HOST" : "my-emulator.com" }, "my-emulator.com" ),
2198- (None , {"STORAGE_EMULATOR_HOST" : "http://my-emulator.com" }, "my-emulator.com" ),
2199- (None , {"STORAGE_EMULATOR_HOST" : "" }, "storage.googleapis.com" ),
2199+ (
2200+ None ,
2201+ {"STORAGE_EMULATOR_HOST" : "http://my-emulator.com" },
2202+ "my-emulator.com" ,
2203+ True ,
2204+ ),
2205+ (
2206+ None ,
2207+ {"STORAGE_EMULATOR_HOST" : "https://my-emulator.com" },
2208+ "my-emulator.com" ,
2209+ False ,
2210+ ),
2211+ (None , {"STORAGE_EMULATOR_HOST" : "" }, "storage.googleapis.com" , False ),
22002212 ],
22012213)
22022214async def test_get_control_plane_client_endpoint (
2203- endpoint_url , env_updates , expected_host
2215+ endpoint_url , env_updates , expected_host , expected_insecure
22042216):
22052217 fs_kwargs = {"token" : "anon" }
22062218 if endpoint_url :
22072219 fs_kwargs ["endpoint_url" ] = endpoint_url
22082220
2209- fs = ExtendedGcsFileSystem (** fs_kwargs )
2210-
22112221 mock_transport_cls = mock .Mock ()
22122222 mock_channel = mock .Mock ()
22132223 mock_transport_cls .create_channel .return_value = mock_channel
@@ -2220,16 +2230,22 @@ async def test_get_control_plane_client_endpoint(
22202230 "get_transport_class" ,
22212231 return_value = mock_transport_cls ,
22222232 ),
2233+ mock .patch ("grpc.aio.insecure_channel" ) as mock_insecure_channel ,
22232234 mock .patch .dict (os .environ , env_updates ),
22242235 ):
2225- # Clear cached client to force re-initialization
2226- fs . _storage_control_client = None
2236+ ExtendedGcsFileSystem . clear_instance_cache ()
2237+ fs = ExtendedGcsFileSystem ( ** fs_kwargs )
22272238
22282239 await fs ._get_control_plane_client ()
22292240
2230- mock_transport_cls .create_channel .assert_called_once ()
2231- kwargs = mock_transport_cls .create_channel .call_args .kwargs
2232- assert kwargs .get ("host" ) == expected_host
2241+ if expected_insecure :
2242+ mock_insecure_channel .assert_called_once_with (
2243+ expected_host , options = mock .ANY
2244+ )
2245+ else :
2246+ mock_transport_cls .create_channel .assert_called_once ()
2247+ kwargs = mock_transport_cls .create_channel .call_args .kwargs
2248+ assert kwargs .get ("host" ) == expected_host
22332249
22342250
22352251def test_extended_gcsfs_retry_init ():
0 commit comments