Skip to content

test(spanner): clear context-aware mTLS env var in unit tests#17838

Open
sakthivelmanii wants to merge 1 commit into
mainfrom
fix-spanner-mtls-tests
Open

test(spanner): clear context-aware mTLS env var in unit tests#17838
sakthivelmanii wants to merge 1 commit into
mainfrom
fix-spanner-mtls-tests

Conversation

@sakthivelmanii

Copy link
Copy Markdown
Contributor

Unset CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE in mTLS unit tests to prevent failures in Google and Kokoro CI environments.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@sakthivelmanii
sakthivelmanii requested review from a team as code owners July 23, 2026 08:31

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the GAPIC generator templates and Google Cloud Spanner unit tests to properly handle the CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE environment variable by popping it during mTLS endpoint tests. It also sets GOOGLE_API_USE_CLIENT_CERTIFICATE to "false" when testing specific GOOGLE_API_USE_MTLS_ENDPOINT behaviors. The reviewer recommends also explicitly setting CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE to "false" in those same test cases to avoid test failures in environments where it is set to "true".


# Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never".
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never", "GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent test failures in environments where CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE is set to "true", we should also explicitly set it to "false" in this mock.patch.dict call, similar to how GOOGLE_API_USE_CLIENT_CERTIFICATE is handled.

    with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never", "GOOGLE_API_USE_CLIENT_CERTIFICATE": "false", "CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE": "false"}):


# Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always".
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}):
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always", "GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent test failures in environments where CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE is set to "true", we should also explicitly set it to "false" in this mock.patch.dict call, similar to how GOOGLE_API_USE_CLIENT_CERTIFICATE is handled.

    with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always", "GOOGLE_API_USE_CLIENT_CERTIFICATE": "false", "CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE": "false"}):

@sakthivelmanii
sakthivelmanii force-pushed the fix-spanner-mtls-tests branch 7 times, most recently from 1be920c to 1f56844 Compare July 23, 2026 10:44
Unset CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE in mTLS unit tests to prevent failures in Google and Kokoro CI environments.
@sakthivelmanii
sakthivelmanii force-pushed the fix-spanner-mtls-tests branch from 1f56844 to a03427a Compare July 23, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants