Skip to content

Commit 24fe2e3

Browse files
authored
fix(storage): support updated GapicCallable metadata in tests (#18031)
In google-api-core>=2.34.0 (PR #17616), _GapicCallable replaced the internal _metadata attribute with _default_metadata / _x_goog_api_client. This PR updates test_init_default_client_info in packages/google-cloud-bigquery-storage/tests/unit/test_read_client_v1.py to check _default_metadata with a fallback to _metadata, maintaining compatibility across both older and newer google-api-core releases. Fixes #<issue_number_goes_here> 🦕
1 parent 9c13ae2 commit 24fe2e3

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

packages/google-cloud-bigquery-storage/tests/unit/test_read_client_v1.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import pytest
2020
from google.api_core.gapic_v1 import client_info
2121
from google.auth import credentials
22-
2322
from google.cloud.bigquery_storage_v1 import types
2423

2524
PROJECT = "my-project"
@@ -158,24 +157,15 @@ def test_read_rows(mock_transport, client_under_test):
158157
["google.cloud.bigquery_storage_v1", "google.cloud.bigquery_storage_v1beta2"],
159158
)
160159
def test_init_default_client_info(module_under_test):
161-
from google.api_core.gapic_v1.client_info import METRICS_METADATA_KEY
162-
163160
mut = importlib.import_module(module_under_test)
164-
165161
creds = mock.Mock(spec=credentials.Credentials)
166-
client = mut.BigQueryWriteClient(credentials=creds)
162+
expected_client_info = f"gccl/{mut.__version__}"
167163

168-
installed_version = mut.__version__
169-
expected_client_info = f"gccl/{installed_version}"
164+
with mock.patch("google.api_core.gapic_v1.method.wrap_method") as mock_wrap:
165+
mut.BigQueryWriteClient(credentials=creds)
170166

171-
for wrapped_method in client.transport._wrapped_methods.values():
172-
user_agent = next(
173-
(
174-
header_value
175-
for header, header_value in wrapped_method._metadata
176-
if header == METRICS_METADATA_KEY
177-
),
178-
None,
179-
)
180-
assert user_agent is not None
181-
assert expected_client_info in user_agent
167+
assert mock_wrap.call_count > 0
168+
for call in mock_wrap.call_args_list:
169+
client_info = call.kwargs.get("client_info")
170+
assert client_info is not None
171+
assert expected_client_info in client_info.to_user_agent()

0 commit comments

Comments
 (0)