Skip to content

Commit e0ce8c5

Browse files
authored
Adding cleanup for Pub / Sub topic in logging system test. (googleapis#4532)
1 parent cc2c07c commit e0ce8c5

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

logging/tests/system.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,17 +414,16 @@ def test_create_sink_storage_bucket(self):
414414
self.assertTrue(sink.exists())
415415

416416
def test_create_sink_pubsub_topic(self):
417-
import uuid
418-
419417
from google.cloud import pubsub_v1
420418

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

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

430429
policy = publisher.get_iam_policy(topic_path)
@@ -439,7 +438,6 @@ def test_create_sink_pubsub_topic(self):
439438
sink = Config.CLIENT.sink(SINK_NAME, DEFAULT_FILTER, TOPIC_URI)
440439
self.assertFalse(sink.exists())
441440
sink.create()
442-
publisher.delete_topic(topic_path)
443441
self.assertTrue(sink.exists())
444442

445443
def _init_bigquery_dataset(self):
@@ -517,3 +515,13 @@ def test_update_sink(self):
517515
sink.update()
518516
self.assertEqual(sink.filter_, UPDATED_FILTER)
519517
self.assertEqual(sink.destination, dataset_uri)
518+
519+
520+
class _DeleteWrapper(object):
521+
522+
def __init__(self, publisher, topic_path):
523+
self.publisher = publisher
524+
self.topic_path = topic_path
525+
526+
def delete(self):
527+
self.publisher.delete_topic(self.topic_path)

0 commit comments

Comments
 (0)