1313# limitations under the License.
1414
1515require "minitest/focus"
16+ require "minitest/mock"
1617require "ostruct"
1718
1819require "google/cloud/pubsub"
@@ -67,7 +68,7 @@ def stop! *_args
6768def mock_pubsub
6869 Google ::Cloud ::PubSub . stub_new do |*args |
6970 credentials = OpenStruct . new ( client : OpenStruct . new ( updater_proc : Proc . new { } ) )
70- pubsub = Google ::Cloud ::PubSub ::Project . new ( Google ::Cloud ::PubSub ::Service . new ( "my-project" , credentials ) )
71+ pubsub = Google ::Cloud ::PubSub ::Project . new ( Google ::Cloud ::PubSub ::Service . new ( "my-project" , credentials , logger : Google :: Cloud :: PubSub :: InternalLogger . new ( nil ) ) )
7172
7273 pubsub . service . mocked_topic_admin = Minitest ::Mock . new
7374 pubsub . service . mocked_subscription_admin = Minitest ::Mock . new
@@ -94,14 +95,14 @@ def mock_pubsub
9495
9596 doctest . before "Google::Cloud" do
9697 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
97- mock_topic_admin . expect :publish , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
98+ mock_topic_admin . expect :publish_internal , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
9899 mock_topic_admin . expect :get_topic , topic_resp , topic : topic_path ( "my-topic" )
99100 end
100101 end
101102
102103 doctest . before "Google::Cloud::PubSub" do
103104 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
104- mock_topic_admin . expect :publish , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
105+ mock_topic_admin . expect :publish_internal , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
105106 mock_topic_admin . expect :get_topic , topic_resp , topic : topic_path ( "my-topic" )
106107 end
107108 end
@@ -110,7 +111,7 @@ def mock_pubsub
110111
111112 doctest . before "Google::Cloud::PubSub::Message" do
112113 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
113- mock_topic_admin . expect :publish , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
114+ mock_topic_admin . expect :publish_internal , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
114115 mock_topic_admin . expect :get_topic , topic_resp , topic : topic_path ( "my-topic" )
115116 mock_subscription_admin . expect :get_subscription , subscription_resp , subscription : subscription_path ( "my-topic-sub" )
116117 mock_subscription_admin . expect :streaming_pull , [ OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) ] . to_enum , [ Enumerator , Hash ]
@@ -125,7 +126,7 @@ def mock_pubsub
125126
126127 doctest . before "Google::Cloud::PubSub::Project" do
127128 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
128- mock_topic_admin . expect :publish , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
129+ mock_topic_admin . expect :publish_internal , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
129130 mock_topic_admin . expect :get_topic , topic_resp , topic : topic_path ( "my-topic" )
130131 end
131132 end
@@ -140,7 +141,7 @@ def mock_pubsub
140141 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
141142 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
142143 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
143- mock_subscription_admin . expect :acknowledge , nil , [ "projects/my-project/subscriptions/my-sub" , [ "2" ] , Hash ]
144+ mock_subscription_admin . expect :acknowledge_internal , nil , [ "projects/my-project/subscriptions/my-sub" , [ "2" ] , Hash ]
144145 end
145146 end
146147
@@ -165,14 +166,14 @@ def mock_pubsub
165166 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
166167 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
167168 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
168- mock_subscription_admin . expect :modify_ack_deadline , nil , [ Hash ]
169+ mock_subscription_admin . expect :modify_ack_deadline_internal , nil , [ Hash ]
169170 end
170171 end
171172
172173 doctest . before "Google::Cloud::PubSub::ReceivedMessage#reject!" do
173174 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
174175 mock_subscription_admin . expect :get_subscription , subscription_resp , subscription : subscription_path ( "my-topic-sub" )
175- mock_subscription_admin . expect :pull , OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) , [ Hash ]
176+ mock_subscription_admin . expect :pull_internal , OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) , [ Hash ]
176177 mock_subscription_admin . expect :streaming_pull , [ OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) ] . to_enum , [ Enumerator , Hash ]
177178 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
178179 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
@@ -190,16 +191,16 @@ def mock_pubsub
190191 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
191192 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
192193 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
193- mock_subscription_admin . expect :acknowledge , nil , [ Hash ]
194+ mock_subscription_admin . expect :acknowledge_internal , nil , [ Hash ]
194195 end
195196 end
196197
197198 doctest . before "Google::Cloud::PubSub::Subscriber#wait_for_messages" do
198199 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
199200 mock_subscription_admin . expect :get_subscription , subscription_resp ( "my-topic-sub" ) , subscription : subscription_path ( "my-topic-sub" )
200- mock_subscription_admin . expect :pull , OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) ,
201+ mock_subscription_admin . expect :pull_internal , OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) ,
201202 subscription : subscription_path ( "my-topic-sub" ) , max_messages : 100 , return_immediately : false
202- mock_subscription_admin . expect :acknowledge , nil , subscription : subscription_path ( "my-topic-sub" ) , ack_ids : [ "2" ]
203+ mock_subscription_admin . expect :acknowledge_internal , nil , subscription : subscription_path ( "my-topic-sub" ) , ack_ids : [ "2" ]
203204 end
204205 end
205206
@@ -213,27 +214,27 @@ def mock_pubsub
213214 doctest . before "Google::Cloud::PubSub::Subscriber#pull@The `immediate: false` option is now recommended to avoid adverse impacts on pull operations:" do
214215 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
215216 mock_subscription_admin . expect :get_subscription , subscription_resp ( "my-topic-sub" ) , subscription : subscription_path ( "my-topic-sub" )
216- mock_subscription_admin . expect :pull , OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) ,
217+ mock_subscription_admin . expect :pull_internal , OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) ,
217218 subscription : subscription_path ( "my-topic-sub" ) , max_messages : 100 , return_immediately : false
218- mock_subscription_admin . expect :acknowledge , nil , subscription : subscription_path ( "my-topic-sub" ) , ack_ids : [ "2" ]
219+ mock_subscription_admin . expect :acknowledge_internal , nil , subscription : subscription_path ( "my-topic-sub" ) , ack_ids : [ "2" ]
219220 end
220221 end
221222
222223 doctest . before "Google::Cloud::PubSub::Subscriber#pull@A maximum number of messages returned can also be specified:" do
223224 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
224225 mock_subscription_admin . expect :get_subscription , subscription_resp ( "my-topic-sub" ) , subscription : subscription_path ( "my-topic-sub" )
225- mock_subscription_admin . expect :pull , OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) ,
226+ mock_subscription_admin . expect :pull_internal , OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) ,
226227 subscription : subscription_path ( "my-topic-sub" ) , max_messages : 10 , return_immediately : false
227- mock_subscription_admin . expect :acknowledge , nil , subscription : subscription_path ( "my-topic-sub" ) , ack_ids : [ "2" ]
228+ mock_subscription_admin . expect :acknowledge_internal , nil , subscription : subscription_path ( "my-topic-sub" ) , ack_ids : [ "2" ]
228229 end
229230 end
230231
231232 doctest . before "Google::Cloud::PubSub::Subscriber#modify_ack_deadline" do
232233 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
233234 mock_subscription_admin . expect :get_subscription , subscription_resp , subscription : subscription_path ( "my-topic-sub" )
234- mock_subscription_admin . expect :pull , OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) ,
235+ mock_subscription_admin . expect :pull_internal , OpenStruct . new ( received_messages : [ Google ::Cloud ::PubSub ::V1 ::ReceivedMessage . new ( ack_id : "2" , message : pubsub_message ) ] ) ,
235236 subscription : subscription_path ( "my-sub" ) , max_messages : 100 , return_immediately : false
236- mock_subscription_admin . expect :modify_ack_deadline , nil , subscription : subscription_path ( "my-sub" ) , ack_ids : [ "2" ] , ack_deadline_seconds : 120
237+ mock_subscription_admin . expect :modify_ack_deadline_internal , nil , subscription : subscription_path ( "my-sub" ) , ack_ids : [ "2" ] , ack_deadline_seconds : 120
237238
238239
239240 end
@@ -262,7 +263,7 @@ def mock_pubsub
262263 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
263264 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
264265 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
265- mock_subscription_admin . expect :acknowledge , nil , [ "projects/my-project/subscriptions/my-ordered-topic-sub" , [ "2" ] , Hash ]
266+ mock_subscription_admin . expect :acknowledge_internal , nil , [ "projects/my-project/subscriptions/my-ordered-topic-sub" , [ "2" ] , Hash ]
266267 end
267268 end
268269
@@ -276,7 +277,7 @@ def mock_pubsub
276277 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
277278 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
278279 mock_subscription_admin . expect :streaming_pull , [ ] . to_enum , [ Enumerator , Hash ]
279- mock_subscription_admin . expect :acknowledge , nil , [ Hash ]
280+ mock_subscription_admin . expect :acknowledge_internal , nil , [ Hash ]
280281 end
281282 end
282283
@@ -286,28 +287,34 @@ def mock_pubsub
286287 doctest . before "Google::Cloud::PubSub::Publisher" do
287288 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
288289 mock_topic_admin . expect :get_topic , topic_resp , topic : topic_path ( "my-topic-only" )
289- mock_topic_admin . expect :publish , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
290+ mock_topic_admin . expect :publish_internal , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
291+ end
292+ end
293+
294+ doctest . before "Google::Cloud::PubSub::Publisher#reload!" do
295+ mock_pubsub do |mock_topic_admin , mock_subscription_admin |
296+ mock_topic_admin . expect :get_topic , topic_resp , topic : topic_path ( "my-topic" )
290297 end
291298 end
292299
293300 doctest . before "Google::Cloud::PubSub::Publisher#async_publisher" do
294301 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
295302 mock_topic_admin . expect :get_topic , topic_resp , topic : topic_path ( "my-topic" )
296- mock_topic_admin . expect :publish , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
303+ mock_topic_admin . expect :publish_internal , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
297304 end
298305 end
299306
300307 doctest . before "Google::Cloud::PubSub::Publisher#publish" do
301308 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
302309 mock_topic_admin . expect :get_topic , topic_resp , topic : topic_path ( "my-topic" )
303- mock_topic_admin . expect :publish , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
310+ mock_topic_admin . expect :publish_internal , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
304311 end
305312 end
306313
307314 doctest . before "Google::Cloud::PubSub::Publisher#publish@Additionally, a message can be published with attributes:" do
308315 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
309316 mock_topic_admin . expect :get_topic , topic_resp , topic : topic_path ( "my-topic" )
310- mock_topic_admin . expect :publish , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
317+ mock_topic_admin . expect :publish_internal , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
311318 end
312319 end
313320
@@ -319,14 +326,14 @@ def mock_pubsub
319326 pubsub_message ( "task 2 completed" , { "foo" => "baz" } ) ,
320327 pubsub_message ( "task 3 completed" , { "foo" => "bif" } )
321328 ]
322- mock_topic_admin . expect :publish , OpenStruct . new ( message_ids : [ "1" , "2" , "3" ] ) , [ Hash ]
329+ mock_topic_admin . expect :publish_internal , OpenStruct . new ( message_ids : [ "1" , "2" , "3" ] ) , [ Hash ]
323330 end
324331 end
325332
326333 doctest . before "Google::Cloud::PubSub::Publisher#publish@Ordered messages are supported using ordering_key:" do
327334 mock_pubsub do |mock_topic_admin , mock_subscription_admin |
328335 mock_topic_admin . expect :get_topic , topic_resp , topic : topic_path ( "my-ordered-topic" )
329- mock_topic_admin . expect :publish , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
336+ mock_topic_admin . expect :publish_internal , OpenStruct . new ( message_ids : [ "1" ] ) , [ Hash ]
330337 end
331338 end
332339
@@ -347,7 +354,7 @@ def mock_pubsub
347354 pubsub_message ( "task 2 completed" , { "foo" => "baz" } ) ,
348355 pubsub_message ( "task 3 completed" , { "foo" => "bif" } )
349356 ]
350- mock_topic_admin . expect :publish , OpenStruct . new ( message_ids : [ "1" , "2" , "3" ] ) , [ Hash ]
357+ mock_topic_admin . expect :publish_internal , OpenStruct . new ( message_ids : [ "1" , "2" , "3" ] ) , [ Hash ]
351358 end
352359 end
353360end
0 commit comments