Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions tests/unit/pubsub_v1/publisher/test_publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,28 @@ def test_init_w_api_endpoint(creds):
client_options = {"api_endpoint": "testendpoint.google.com"}
client = publisher.Client(client_options=client_options, credentials=creds)

# Behavior to include dns prefix changed in gRPCv1.63
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
_EXPECTED_TARGET = "dns:///testendpoint.google.com:443"
else:
_EXPECTED_TARGET = "testendpoint.google.com:443"
Comment on lines +136 to +141
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be moved to a help function to avoid duplication. I'll go ahead and approve since the builds are failing at main but consider creating a follow up PR to reduce code duplication.

assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == "testendpoint.google.com:443"
) == _EXPECTED_TARGET


def test_init_w_empty_client_options(creds):
client = publisher.Client(client_options={}, credentials=creds)

# Behavior to include dns prefix changed in gRPCv1.63
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
_EXPECTED_TARGET = "dns:///pubsub.googleapis.com:443"
else:
_EXPECTED_TARGET = "pubsub.googleapis.com:443"
assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == publisher_client.PublisherClient.SERVICE_ADDRESS
) == _EXPECTED_TARGET


def test_init_client_options_pass_through():
Expand Down Expand Up @@ -182,7 +193,13 @@ def test_init_emulator(monkeypatch):
# Sadly, there seems to be no good way to do this without poking at
# the private API of gRPC.
channel = client._transport.publish._channel
assert channel.target().decode("utf8") == "/foo/bar:123"
# Behavior to include dns prefix changed in gRPCv1.63
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
_EXPECTED_TARGET = "dns:////foo/bar:123"
else:
_EXPECTED_TARGET = "/foo/bar:123"
assert channel.target().decode("utf8") == _EXPECTED_TARGET


def test_message_ordering_enabled(creds):
Expand Down
25 changes: 21 additions & 4 deletions tests/unit/pubsub_v1/subscriber/test_subscriber_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,28 @@ def test_init_w_api_endpoint(creds):
client_options = {"api_endpoint": "testendpoint.google.com"}
client = subscriber.Client(client_options=client_options, credentials=creds)

# Behavior to include dns prefix changed in gRPCv1.63
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
_EXPECTED_TARGET = "dns:///testendpoint.google.com:443"
else:
_EXPECTED_TARGET = "testendpoint.google.com:443"
assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == "testendpoint.google.com:443"
) == _EXPECTED_TARGET


def test_init_w_empty_client_options(creds):
client = subscriber.Client(client_options={}, credentials=creds)

# Behavior to include dns prefix changed in gRPCv1.63
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
_EXPECTED_TARGET = "dns:///pubsub.googleapis.com:443"
else:
_EXPECTED_TARGET = "pubsub.googleapis.com:443"
assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == subscriber_client.SubscriberClient.SERVICE_ADDRESS
) == _EXPECTED_TARGET


def test_init_client_options_pass_through():
Expand Down Expand Up @@ -115,7 +126,13 @@ def test_init_emulator(monkeypatch):
# Sadly, there seems to be no good way to do this without poking at
# the private API of gRPC.
channel = client._transport.pull._channel
assert channel.target().decode("utf8") == "/baz/bacon:123"
# Behavior to include dns prefix changed in gRPCv1.63
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
_EXPECTED_TARGET = "dns:////baz/bacon:123"
else:
_EXPECTED_TARGET = "/baz/bacon:123"
assert channel.target().decode("utf8") == _EXPECTED_TARGET


def test_class_method_factory():
Expand Down