forked from testcontainers/testcontainers-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_google.py
More file actions
28 lines (23 loc) · 1.06 KB
/
test_google.py
File metadata and controls
28 lines (23 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from testcontainers.google import PubSubContainer
from testcontainers.core.waiting_utils import wait_for_logs
from queue import Queue
def test_pubsub_container():
with PubSubContainer() as pubsub:
wait_for_logs(pubsub, r"Server started, listening on \d+", timeout=10)
# Create a new topic
publisher = pubsub.get_publisher_client()
topic_path = publisher.topic_path(pubsub.project, "my-topic")
publisher.create_topic(topic_path)
# Create a subscription
subscriber = pubsub.get_subscriber_client()
subscription_path = subscriber.subscription_path(pubsub.project,
"my-subscription")
subscriber.create_subscription(subscription_path, topic_path)
# Publish a message
publisher.publish(topic_path, b"Hello world!")
# Receive the message
queue = Queue()
subscriber.subscribe(subscription_path, queue.put)
message = queue.get(timeout=1)
assert message.data == b"Hello world!"
message.ack()