Skip to content

Commit c6abed4

Browse files
author
remi Taylor
committed
Add delete_topic and delete_subscription
1 parent 070bfb2 commit c6abed4

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

pubsub/sample.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ def create_topic
3030
# [END create_topic]
3131
end
3232

33+
def delete_topic
34+
# [START delete_topic]
35+
gcloud = Google::Cloud.new "my-gcp-project-id"
36+
pubsub = gcloud.pubsub
37+
topic = pubsub.topic "my-topic"
38+
39+
topic.delete
40+
41+
puts "Deleted topic my-topic"
42+
# [END delete_topic]
43+
end
44+
3345
def create_subscription
3446
# [START create_subscription]
3547
gcloud = Google::Cloud.new "my-gcp-project-id"
@@ -42,6 +54,19 @@ def create_subscription
4254
# [END create_subscription]
4355
end
4456

57+
def delete_subscription
58+
# [START delete_subscription]
59+
gcloud = Google::Cloud.new "my-gcp-project-id"
60+
pubsub = gcloud.pubsub
61+
topic = pubsub.topic "my-topic"
62+
subscription = topic.subscription "my-subscription"
63+
64+
subscription.delete
65+
66+
puts "Deleted subscription my-subscription"
67+
# [END delete_subscription]
68+
end
69+
4570
def create_push_subscription
4671
# [START create_push_subscription]
4772
gcloud = Google::Cloud.new "my-gcp-project-id"

pubsub/spec/sample_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ def expect_with_retry attempts: 5
6161
expect(topic.name).to include(TOPIC_NAME)
6262
end
6363

64+
it "deletes topic" do
65+
@pubsub.create_topic TOPIC_NAME
66+
expect(@pubsub.topic TOPIC_NAME).not_to be nil
67+
68+
expect { delete_topic }.to output("Deleted topic #{TOPIC_NAME}\n").to_stdout
69+
70+
expect(@pubsub.topic TOPIC_NAME).to be nil
71+
end
72+
6473
it "creates subscription" do
6574
expect(@pubsub.subscription(SUBSCRIPTION_NAME)).to be nil
6675
@pubsub.create_topic TOPIC_NAME
@@ -74,6 +83,22 @@ def expect_with_retry attempts: 5
7483
expect(subscription.topic.name).to include(TOPIC_NAME)
7584
end
7685

86+
it "deletes subscription" do
87+
topic = @pubsub.create_topic TOPIC_NAME
88+
@pubsub.create_subscription(
89+
TOPIC_NAME,
90+
SUBSCRIPTION_NAME,
91+
autocreate: true
92+
)
93+
expect(topic.subscription SUBSCRIPTION_NAME).not_to be nil
94+
95+
expect { delete_subscription }.to output(
96+
"Deleted subscription #{SUBSCRIPTION_NAME}\n"
97+
).to_stdout
98+
99+
expect(topic.subscription SUBSCRIPTION_NAME).to be nil
100+
end
101+
77102
it "creates push subscription" do
78103
subscription_name = "my-subscription-push"
79104

0 commit comments

Comments
 (0)