Skip to content

Commit 1276189

Browse files
authored
fix: mock out configure_mtls_channel in rest transport for testing (#1920)
1 parent 5614db0 commit 1276189

8 files changed

Lines changed: 32 additions & 24 deletions

File tree

packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,10 @@ def test_{{ service.client_name|snake_case }}_client_api_endpoint(client_class):
664664
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
665665
# use ClientOptions.api_endpoint as the api endpoint regardless.
666666
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
667-
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
668-
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
669-
assert client.api_endpoint == api_override
667+
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
668+
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
669+
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
670+
assert client.api_endpoint == api_override
670671

671672
# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
672673
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,10 @@ def test_asset_service_client_client_api_endpoint(client_class):
599599
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
600600
# use ClientOptions.api_endpoint as the api endpoint regardless.
601601
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
602-
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
603-
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
604-
assert client.api_endpoint == api_override
602+
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
603+
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
604+
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
605+
assert client.api_endpoint == api_override
605606

606607
# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
607608
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.

packages/gapic-generator/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,10 @@ def test_iam_credentials_client_client_api_endpoint(client_class):
589589
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
590590
# use ClientOptions.api_endpoint as the api endpoint regardless.
591591
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
592-
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
593-
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
594-
assert client.api_endpoint == api_override
592+
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
593+
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
594+
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
595+
assert client.api_endpoint == api_override
595596

596597
# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
597598
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.

packages/gapic-generator/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,10 @@ def test_eventarc_client_client_api_endpoint(client_class):
609609
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
610610
# use ClientOptions.api_endpoint as the api endpoint regardless.
611611
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
612-
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
613-
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
614-
assert client.api_endpoint == api_override
612+
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
613+
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
614+
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
615+
assert client.api_endpoint == api_override
615616

616617
# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
617618
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.

packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,10 @@ def test_config_service_v2_client_client_api_endpoint(client_class):
575575
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
576576
# use ClientOptions.api_endpoint as the api endpoint regardless.
577577
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
578-
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
579-
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
580-
assert client.api_endpoint == api_override
578+
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
579+
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
580+
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
581+
assert client.api_endpoint == api_override
581582

582583
# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
583584
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.

packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,10 @@ def test_logging_service_v2_client_client_api_endpoint(client_class):
576576
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
577577
# use ClientOptions.api_endpoint as the api endpoint regardless.
578578
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
579-
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
580-
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
581-
assert client.api_endpoint == api_override
579+
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
580+
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
581+
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
582+
assert client.api_endpoint == api_override
582583

583584
# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
584585
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.

packages/gapic-generator/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,10 @@ def test_metrics_service_v2_client_client_api_endpoint(client_class):
574574
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
575575
# use ClientOptions.api_endpoint as the api endpoint regardless.
576576
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
577-
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
578-
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
579-
assert client.api_endpoint == api_override
577+
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
578+
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
579+
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
580+
assert client.api_endpoint == api_override
580581

581582
# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
582583
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.

packages/gapic-generator/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,10 @@ def test_cloud_redis_client_client_api_endpoint(client_class):
600600
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
601601
# use ClientOptions.api_endpoint as the api endpoint regardless.
602602
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
603-
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
604-
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
605-
assert client.api_endpoint == api_override
603+
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
604+
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
605+
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
606+
assert client.api_endpoint == api_override
606607

607608
# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
608609
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.

0 commit comments

Comments
 (0)