Skip to content

Commit

Permalink
fix: mock out configure_mtls_channel in rest transport for testing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmayr committed Jan 31, 2024
1 parent e5a55c1 commit 9ade50d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,10 @@ def test_{{ service.client_name|snake_case }}_client_api_endpoint(client_class):
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
# use ClientOptions.api_endpoint as the api endpoint regardless.
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override

# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,10 @@ def test_asset_service_client_client_api_endpoint(client_class):
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
# use ClientOptions.api_endpoint as the api endpoint regardless.
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override

# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,10 @@ def test_iam_credentials_client_client_api_endpoint(client_class):
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
# use ClientOptions.api_endpoint as the api endpoint regardless.
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override

# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,10 @@ def test_eventarc_client_client_api_endpoint(client_class):
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
# use ClientOptions.api_endpoint as the api endpoint regardless.
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override

# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,10 @@ def test_config_service_v2_client_client_api_endpoint(client_class):
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
# use ClientOptions.api_endpoint as the api endpoint regardless.
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override

# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,10 @@ def test_logging_service_v2_client_client_api_endpoint(client_class):
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
# use ClientOptions.api_endpoint as the api endpoint regardless.
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override

# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,10 @@ def test_metrics_service_v2_client_client_api_endpoint(client_class):
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
# use ClientOptions.api_endpoint as the api endpoint regardless.
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override

# If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never",
# use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,10 @@ def test_cloud_redis_client_client_api_endpoint(client_class):
# If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true",
# use ClientOptions.api_endpoint as the api endpoint regardless.
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override
with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"):
options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override)
client = client_class(client_options=options, credentials=_AnonymousCredentialsWithUniverseDomain())
assert client.api_endpoint == api_override

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

0 comments on commit 9ade50d

Please sign in to comment.