Skip to content

Commit 275244d

Browse files
committed
update goldens
1 parent d0ccc57 commit 275244d

40 files changed

Lines changed: 2916 additions & 6452 deletions

File tree

packages/gapic-generator/tests/integration/goldens/asset/google/cloud/asset_v1/_compat.py

100644100755
Lines changed: 134 additions & 294 deletions
Large diffs are not rendered by default.

packages/gapic-generator/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py

Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from google.api_core import client_options as client_options_lib
2828
from google.api_core import exceptions as core_exceptions
2929
from google.api_core import gapic_v1
30+
from google.cloud.asset_v1 import _compat as client_utils
3031
from google.api_core import retry as retries
3132
from google.auth import credentials as ga_credentials # type: ignore
3233
from google.auth.transport import mtls # type: ignore
@@ -100,43 +101,9 @@ def get_transport_class(cls,
100101
class AssetServiceClient(metaclass=AssetServiceClientMeta):
101102
"""Asset service definition."""
102103

103-
@staticmethod
104-
def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]:
105-
"""Converts api endpoint to mTLS endpoint.
106-
107-
Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
108-
"*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
109-
Args:
110-
api_endpoint (Optional[str]): the api endpoint to convert.
111-
Returns:
112-
Optional[str]: converted mTLS api endpoint.
113-
"""
114-
if not api_endpoint:
115-
return api_endpoint
116-
117-
mtls_endpoint_re = re.compile(
118-
r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
119-
)
120-
121-
m = mtls_endpoint_re.match(api_endpoint)
122-
if m is None:
123-
# Could not parse api_endpoint; return as-is.
124-
return api_endpoint
125-
126-
name, mtls, sandbox, googledomain = m.groups()
127-
if mtls or not googledomain:
128-
return api_endpoint
129-
130-
if sandbox:
131-
return api_endpoint.replace(
132-
"sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
133-
)
134-
135-
return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
136-
137104
# Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
138105
DEFAULT_ENDPOINT = "cloudasset.googleapis.com"
139-
DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
106+
DEFAULT_MTLS_ENDPOINT = client_utils.get_default_mtls_endpoint(
140107
DEFAULT_ENDPOINT
141108
)
142109

@@ -450,30 +417,34 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag):
450417
return client_cert_source
451418

452419
@staticmethod
453-
def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str:
420+
def _get_api_endpoint(
421+
api_override: Optional[str],
422+
client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]],
423+
universe_domain: str,
424+
use_mtls_endpoint: str,
425+
) -> Optional[str]:
454426
"""Return the API endpoint used by the client.
455427
456428
Args:
457-
api_override (str): The API endpoint override. If specified, this is always
429+
api_override (Optional[str]): The API endpoint override. If specified, this is always
458430
the return value of this function and the other arguments are not used.
459-
client_cert_source (bytes): The client certificate source used by the client.
431+
client_cert_source (Union[Callable[[], Tuple[bytes, bytes]], None]): The client certificate source used by the client.
460432
universe_domain (str): The universe domain used by the client.
461433
use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
462434
Possible values are "always", "auto", or "never".
463435
464436
Returns:
465-
str: The API endpoint to be used by the client.
437+
Optional[str]: The API endpoint to be used by the client.
466438
"""
467-
if api_override is not None:
468-
api_endpoint = api_override
469-
elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source):
470-
_default_universe = AssetServiceClient._DEFAULT_UNIVERSE
471-
if universe_domain != _default_universe:
472-
raise MutualTLSChannelError(f"mTLS is not supported in any universe other than {_default_universe}.")
473-
api_endpoint = AssetServiceClient.DEFAULT_MTLS_ENDPOINT
474-
else:
475-
api_endpoint = AssetServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=universe_domain)
476-
return api_endpoint
439+
return client_utils.get_api_endpoint(
440+
api_override,
441+
client_cert_source,
442+
universe_domain,
443+
use_mtls_endpoint,
444+
AssetServiceClient._DEFAULT_UNIVERSE,
445+
AssetServiceClient.DEFAULT_MTLS_ENDPOINT,
446+
AssetServiceClient._DEFAULT_ENDPOINT_TEMPLATE,
447+
)
477448

478449
@staticmethod
479450
def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str:
@@ -489,14 +460,11 @@ def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_
489460
Raises:
490461
ValueError: If the universe domain is an empty string.
491462
"""
492-
universe_domain = AssetServiceClient._DEFAULT_UNIVERSE
493-
if client_universe_domain is not None:
494-
universe_domain = client_universe_domain
495-
elif universe_domain_env is not None:
496-
universe_domain = universe_domain_env
497-
if len(universe_domain.strip()) == 0:
498-
raise ValueError("Universe Domain cannot be an empty string.")
499-
return universe_domain
463+
return client_utils.get_universe_domain(
464+
client_universe_domain,
465+
universe_domain_env,
466+
default_universe=AssetServiceClient._DEFAULT_UNIVERSE,
467+
)
500468

501469
def _validate_universe_domain(self):
502470
"""Validates client's and credentials' universe domains are consistent.

packages/gapic-generator/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,6 @@ def set_event_loop():
121121
asyncio.set_event_loop(None)
122122

123123

124-
def test__get_default_mtls_endpoint():
125-
api_endpoint = "example.googleapis.com"
126-
api_mtls_endpoint = "example.mtls.googleapis.com"
127-
sandbox_endpoint = "example.sandbox.googleapis.com"
128-
sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com"
129-
non_googleapi = "api.example.com"
130-
custom_endpoint = ".custom"
131-
132-
assert AssetServiceClient._get_default_mtls_endpoint(None) is None
133-
assert AssetServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint
134-
assert AssetServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint
135-
assert AssetServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint
136-
assert AssetServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint
137-
assert AssetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi
138-
assert AssetServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint
139-
140124
def test__read_environment_variables():
141125
assert AssetServiceClient._read_environment_variables() == (False, "auto", None)
142126

@@ -278,40 +262,6 @@ def test__get_client_cert_source():
278262
assert AssetServiceClient._get_client_cert_source(None, True) is mock_default_cert_source
279263
assert AssetServiceClient._get_client_cert_source(mock_provided_cert_source, "true") is mock_provided_cert_source
280264

281-
@mock.patch.object(AssetServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(AssetServiceClient))
282-
@mock.patch.object(AssetServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(AssetServiceAsyncClient))
283-
def test__get_api_endpoint():
284-
api_override = "foo.com"
285-
mock_client_cert_source = mock.Mock()
286-
default_universe = AssetServiceClient._DEFAULT_UNIVERSE
287-
default_endpoint = AssetServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe)
288-
mock_universe = "bar.com"
289-
mock_endpoint = AssetServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe)
290-
291-
assert AssetServiceClient._get_api_endpoint(api_override, mock_client_cert_source, default_universe, "always") == api_override
292-
assert AssetServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "auto") == AssetServiceClient.DEFAULT_MTLS_ENDPOINT
293-
assert AssetServiceClient._get_api_endpoint(None, None, default_universe, "auto") == default_endpoint
294-
assert AssetServiceClient._get_api_endpoint(None, None, default_universe, "always") == AssetServiceClient.DEFAULT_MTLS_ENDPOINT
295-
assert AssetServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "always") == AssetServiceClient.DEFAULT_MTLS_ENDPOINT
296-
assert AssetServiceClient._get_api_endpoint(None, None, mock_universe, "never") == mock_endpoint
297-
assert AssetServiceClient._get_api_endpoint(None, None, default_universe, "never") == default_endpoint
298-
299-
with pytest.raises(MutualTLSChannelError) as excinfo:
300-
AssetServiceClient._get_api_endpoint(None, mock_client_cert_source, mock_universe, "auto")
301-
assert str(excinfo.value) == "mTLS is not supported in any universe other than googleapis.com."
302-
303-
304-
def test__get_universe_domain():
305-
client_universe_domain = "foo.com"
306-
universe_domain_env = "bar.com"
307-
308-
assert AssetServiceClient._get_universe_domain(client_universe_domain, universe_domain_env) == client_universe_domain
309-
assert AssetServiceClient._get_universe_domain(None, universe_domain_env) == universe_domain_env
310-
assert AssetServiceClient._get_universe_domain(None, None) == AssetServiceClient._DEFAULT_UNIVERSE
311-
312-
with pytest.raises(ValueError) as excinfo:
313-
AssetServiceClient._get_universe_domain("", None)
314-
assert str(excinfo.value) == "Universe Domain cannot be an empty string."
315265

316266
@pytest.mark.parametrize("error_code,cred_info_json,show_cred_info", [
317267
(401, CRED_INFO_JSON, True),
@@ -701,7 +651,7 @@ def test_asset_service_client_get_mtls_endpoint_and_cert_source(client_class):
701651
config_filename = "mock_certificate_config.json"
702652
config_file_content = json.dumps(config_data)
703653
m = mock.mock_open(read_data=config_file_content)
704-
with mock.patch("builtins.open", m), mock.patch("os.path.exists", side_effect=lambda path: os.path.basename(path) == config_filename):
654+
with mock.patch("builtins.open", m):
705655
with mock.patch.dict(
706656
os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": config_filename}
707657
):
@@ -749,7 +699,7 @@ def test_asset_service_client_get_mtls_endpoint_and_cert_source(client_class):
749699
config_filename = "mock_certificate_config.json"
750700
config_file_content = json.dumps(config_data)
751701
m = mock.mock_open(read_data=config_file_content)
752-
with mock.patch("builtins.open", m), mock.patch("os.path.exists", side_effect=lambda path: os.path.basename(path) == config_filename):
702+
with mock.patch("builtins.open", m):
753703
with mock.patch.dict(
754704
os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": config_filename}
755705
):

0 commit comments

Comments
 (0)