Skip to content

Commit 1be920c

Browse files
test(spanner): clear context-aware mTLS env var in unit tests
Unset CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE in mTLS unit tests to prevent failures in Google and Kokoro CI environments.
1 parent 270c7fe commit 1be920c

21 files changed

Lines changed: 43396 additions & 26822 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ def test_{{ service.client_name|snake_case }}_get_mtls_endpoint_and_cert_source(
896896
for config_data, expected_cert_source in test_cases:
897897
env = os.environ.copy()
898898
env.pop("GOOGLE_API_USE_CLIENT_CERTIFICATE", None)
899+
env.pop("CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE", None)
899900
with mock.patch.dict(os.environ, env, clear=True):
900901
config_filename = "mock_certificate_config.json"
901902
config_file_content = json.dumps(config_data)
@@ -943,6 +944,7 @@ def test_{{ service.client_name|snake_case }}_get_mtls_endpoint_and_cert_source(
943944
for config_data, expected_cert_source in test_cases:
944945
env = os.environ.copy()
945946
env.pop("GOOGLE_API_USE_CLIENT_CERTIFICATE", "")
947+
env.pop("CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE", "")
946948
with mock.patch.dict(os.environ, env, clear=True):
947949
config_filename = "mock_certificate_config.json"
948950
config_file_content = json.dumps(config_data)
@@ -963,13 +965,25 @@ def test_{{ service.client_name|snake_case }}_get_mtls_endpoint_and_cert_source(
963965
assert cert_source is expected_cert_source
964966

965967
# Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never".
966-
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
968+
with mock.patch.dict(
969+
os.environ,
970+
{
971+
"GOOGLE_API_USE_MTLS_ENDPOINT": "never",
972+
"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false",
973+
},
974+
):
967975
api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source()
968976
assert api_endpoint == client_class.DEFAULT_ENDPOINT
969977
assert cert_source is None
970978

971979
# Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always".
972-
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}):
980+
with mock.patch.dict(
981+
os.environ,
982+
{
983+
"GOOGLE_API_USE_MTLS_ENDPOINT": "always",
984+
"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false",
985+
},
986+
):
973987
api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source()
974988
assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT
975989
assert cert_source is None

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

Lines changed: 6144 additions & 3819 deletions
Large diffs are not rendered by default.

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

Lines changed: 1744 additions & 971 deletions
Large diffs are not rendered by default.

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

Lines changed: 10321 additions & 6611 deletions
Large diffs are not rendered by default.

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

Lines changed: 3925 additions & 2943 deletions
Large diffs are not rendered by default.

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

Lines changed: 1507 additions & 839 deletions
Large diffs are not rendered by default.

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

Lines changed: 1506 additions & 839 deletions
Large diffs are not rendered by default.

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

Lines changed: 3951 additions & 2945 deletions
Large diffs are not rendered by default.

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

Lines changed: 1507 additions & 839 deletions
Large diffs are not rendered by default.

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

Lines changed: 1527 additions & 841 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)