Skip to content

Commit

Permalink
Adding cleanup for Pub / Sub topic in logging system test. (#4532)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes authored Dec 6, 2017
1 parent cc2c07c commit e0ce8c5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions logging/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,16 @@ def test_create_sink_storage_bucket(self):
self.assertTrue(sink.exists())

def test_create_sink_pubsub_topic(self):
import uuid

from google.cloud import pubsub_v1

SINK_NAME = 'test-create-sink-topic%s' % (_RESOURCE_ID,)
TOPIC_NAME = '%s-%s' % ('systest', str(uuid.uuid4())[0:8])
TOPIC_NAME = 'logging-systest{}'.format(unique_resource_id('-'))

# Create the destination topic, and set up the IAM policy to allow
# Stackdriver Logging to write into it.
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path(Config.CLIENT.project, TOPIC_NAME)
self.to_delete.append(_DeleteWrapper(publisher, topic_path))
publisher.create_topic(topic_path)

policy = publisher.get_iam_policy(topic_path)
Expand All @@ -439,7 +438,6 @@ def test_create_sink_pubsub_topic(self):
sink = Config.CLIENT.sink(SINK_NAME, DEFAULT_FILTER, TOPIC_URI)
self.assertFalse(sink.exists())
sink.create()
publisher.delete_topic(topic_path)
self.assertTrue(sink.exists())

def _init_bigquery_dataset(self):
Expand Down Expand Up @@ -517,3 +515,13 @@ def test_update_sink(self):
sink.update()
self.assertEqual(sink.filter_, UPDATED_FILTER)
self.assertEqual(sink.destination, dataset_uri)


class _DeleteWrapper(object):

def __init__(self, publisher, topic_path):
self.publisher = publisher
self.topic_path = topic_path

def delete(self):
self.publisher.delete_topic(self.topic_path)

0 comments on commit e0ce8c5

Please sign in to comment.