Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .toys/.lib/sample_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def run **params
private

def camelize name
::File.basename(name, ".rb").split("_").map(&:capitalize).join
::File.basename(name, ".rb").split(/[_-]/).map(&:capitalize).join
Comment thread
torreypayne marked this conversation as resolved.
end

def traverse_name mod, name, type
Expand Down
2 changes: 2 additions & 0 deletions google-cloud-bigquery/support/doctest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

require "minitest/focus"
require "minitest/mock"
require "ostruct"

require "google/cloud/bigquery"
require "google/cloud/storage"
Expand Down
2 changes: 2 additions & 0 deletions google-cloud-bigtable/support/doctest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

require "minitest/focus"
require "minitest/mock"
require "ostruct"

require "google/cloud/bigtable"
require "grpc/errors"
Expand Down
2 changes: 2 additions & 0 deletions google-cloud-datastore/support/doctest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

require "minitest/focus"
require "minitest/mock"
require "ostruct"

require "grpc"
require "google/cloud/datastore"
Expand Down
2 changes: 2 additions & 0 deletions google-cloud-dns/support/doctest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

require "minitest/focus"
require "minitest/mock"
require "ostruct"

require "google/cloud/dns"

Expand Down
1 change: 1 addition & 0 deletions google-cloud-error_reporting/support/doctest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

require "minitest/focus"
require "minitest/mock"
require "ostruct"

require "google/cloud/error_reporting"
Expand Down
19 changes: 17 additions & 2 deletions google-cloud-firestore/support/doctest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

require "minitest/focus"
require "minitest/mock"
require "ostruct"

require "google/cloud/firestore"

Expand Down Expand Up @@ -64,8 +66,20 @@ def on_error &block
def last_error
end
end
DocumentListener = StubbedListener
QueryListener = StubbedListener

class DocumentReference
def listen &callback
StubbedListener.new.start
end
alias on_snapshot listen
end

class Query
def listen &callback
StubbedListener.new.start
end
alias on_snapshot listen
end
end
end
end
Expand All @@ -89,6 +103,7 @@ def mock_firestore
doctest.skip "Google::Cloud::Firestore::V1::FirestoreClient"
doctest.skip "Google::Cloud::Firestore::V1beta1::FirestoreClient"
doctest.skip "Google::Cloud::Firestore::Admin::V1::FirestoreAdminClient"
doctest.skip "Google::Cloud::Firestore::BulkWriter"

doctest.before "Google::Cloud#firestore" do
mock_firestore
Expand Down
2 changes: 2 additions & 0 deletions google-cloud-logging/support/doctest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

require "minitest/focus"
require "minitest/mock"
require "ostruct"

require "google/cloud/storage"
require "google/cloud/logging"
Expand Down
59 changes: 33 additions & 26 deletions google-cloud-pubsub/support/doctest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

require "minitest/focus"
require "minitest/mock"
require "ostruct"

require "google/cloud/pubsub"
Expand Down Expand Up @@ -67,7 +68,7 @@ def stop! *_args
def mock_pubsub
Google::Cloud::PubSub.stub_new do |*args|
credentials = OpenStruct.new(client: OpenStruct.new(updater_proc: Proc.new {}))
pubsub = Google::Cloud::PubSub::Project.new(Google::Cloud::PubSub::Service.new("my-project", credentials))
pubsub = Google::Cloud::PubSub::Project.new(Google::Cloud::PubSub::Service.new("my-project", credentials, logger: Google::Cloud::PubSub::InternalLogger.new(nil)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may need syncing with latest https://github.com/googleapis/google-cloud-ruby/pull/36298/changes.

I see "This stack is out-of-date with its base branch"


pubsub.service.mocked_topic_admin = Minitest::Mock.new
pubsub.service.mocked_subscription_admin = Minitest::Mock.new
Expand All @@ -94,14 +95,14 @@ def mock_pubsub

doctest.before "Google::Cloud" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_topic_admin.expect :publish, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :publish_internal, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :get_topic, topic_resp, topic: topic_path("my-topic")
end
end

doctest.before "Google::Cloud::PubSub" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_topic_admin.expect :publish, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :publish_internal, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :get_topic, topic_resp, topic: topic_path("my-topic")
end
end
Expand All @@ -110,7 +111,7 @@ def mock_pubsub

doctest.before "Google::Cloud::PubSub::Message" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_topic_admin.expect :publish, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :publish_internal, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :get_topic, topic_resp, topic: topic_path("my-topic")
mock_subscription_admin.expect :get_subscription, subscription_resp, subscription: subscription_path("my-topic-sub")
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]
Expand All @@ -125,7 +126,7 @@ def mock_pubsub

doctest.before "Google::Cloud::PubSub::Project" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_topic_admin.expect :publish, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :publish_internal, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :get_topic, topic_resp, topic: topic_path("my-topic")
end
end
Expand All @@ -140,7 +141,7 @@ def mock_pubsub
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :acknowledge, nil, ["projects/my-project/subscriptions/my-sub", ["2"], Hash]
mock_subscription_admin.expect :acknowledge_internal, nil, ["projects/my-project/subscriptions/my-sub", ["2"], Hash]
end
end

Expand All @@ -165,14 +166,14 @@ def mock_pubsub
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :modify_ack_deadline, nil, [Hash]
mock_subscription_admin.expect :modify_ack_deadline_internal, nil, [Hash]
end
end

doctest.before "Google::Cloud::PubSub::ReceivedMessage#reject!" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_subscription_admin.expect :get_subscription, subscription_resp, subscription: subscription_path("my-topic-sub")
mock_subscription_admin.expect :pull, OpenStruct.new(received_messages: [Google::Cloud::PubSub::V1::ReceivedMessage.new(ack_id: "2", message: pubsub_message)]), [Hash]
mock_subscription_admin.expect :pull_internal, OpenStruct.new(received_messages: [Google::Cloud::PubSub::V1::ReceivedMessage.new(ack_id: "2", message: pubsub_message)]), [Hash]
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]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
Expand All @@ -190,16 +191,16 @@ def mock_pubsub
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :acknowledge, nil, [Hash]
mock_subscription_admin.expect :acknowledge_internal, nil, [Hash]
end
end

doctest.before "Google::Cloud::PubSub::Subscriber#wait_for_messages" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_subscription_admin.expect :get_subscription, subscription_resp("my-topic-sub"), subscription: subscription_path("my-topic-sub")
mock_subscription_admin.expect :pull, OpenStruct.new(received_messages: [Google::Cloud::PubSub::V1::ReceivedMessage.new(ack_id: "2", message: pubsub_message)]),
mock_subscription_admin.expect :pull_internal, OpenStruct.new(received_messages: [Google::Cloud::PubSub::V1::ReceivedMessage.new(ack_id: "2", message: pubsub_message)]),
subscription: subscription_path("my-topic-sub"), max_messages: 100, return_immediately: false
mock_subscription_admin.expect :acknowledge, nil, subscription: subscription_path("my-topic-sub"), ack_ids: ["2"]
mock_subscription_admin.expect :acknowledge_internal, nil, subscription: subscription_path("my-topic-sub"), ack_ids: ["2"]
end
end

Expand All @@ -213,27 +214,27 @@ def mock_pubsub
doctest.before "Google::Cloud::PubSub::Subscriber#pull@The `immediate: false` option is now recommended to avoid adverse impacts on pull operations:" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_subscription_admin.expect :get_subscription, subscription_resp("my-topic-sub"), subscription: subscription_path("my-topic-sub")
mock_subscription_admin.expect :pull, OpenStruct.new(received_messages: [Google::Cloud::PubSub::V1::ReceivedMessage.new(ack_id: "2", message: pubsub_message)]),
mock_subscription_admin.expect :pull_internal, OpenStruct.new(received_messages: [Google::Cloud::PubSub::V1::ReceivedMessage.new(ack_id: "2", message: pubsub_message)]),
subscription: subscription_path("my-topic-sub"), max_messages: 100, return_immediately: false
mock_subscription_admin.expect :acknowledge, nil, subscription: subscription_path("my-topic-sub"), ack_ids: ["2"]
mock_subscription_admin.expect :acknowledge_internal, nil, subscription: subscription_path("my-topic-sub"), ack_ids: ["2"]
end
end

doctest.before "Google::Cloud::PubSub::Subscriber#pull@A maximum number of messages returned can also be specified:" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_subscription_admin.expect :get_subscription, subscription_resp("my-topic-sub"), subscription: subscription_path("my-topic-sub")
mock_subscription_admin.expect :pull, OpenStruct.new(received_messages: [Google::Cloud::PubSub::V1::ReceivedMessage.new(ack_id: "2", message: pubsub_message)]),
mock_subscription_admin.expect :pull_internal, OpenStruct.new(received_messages: [Google::Cloud::PubSub::V1::ReceivedMessage.new(ack_id: "2", message: pubsub_message)]),
subscription: subscription_path("my-topic-sub"), max_messages: 10, return_immediately: false
mock_subscription_admin.expect :acknowledge, nil, subscription: subscription_path("my-topic-sub"), ack_ids: ["2"]
mock_subscription_admin.expect :acknowledge_internal, nil, subscription: subscription_path("my-topic-sub"), ack_ids: ["2"]
end
end

doctest.before "Google::Cloud::PubSub::Subscriber#modify_ack_deadline" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_subscription_admin.expect :get_subscription, subscription_resp, subscription: subscription_path("my-topic-sub")
mock_subscription_admin.expect :pull, OpenStruct.new(received_messages: [Google::Cloud::PubSub::V1::ReceivedMessage.new(ack_id: "2", message: pubsub_message)]),
mock_subscription_admin.expect :pull_internal, OpenStruct.new(received_messages: [Google::Cloud::PubSub::V1::ReceivedMessage.new(ack_id: "2", message: pubsub_message)]),
subscription: subscription_path("my-sub"), max_messages: 100, return_immediately: false
mock_subscription_admin.expect :modify_ack_deadline, nil, subscription: subscription_path("my-sub"), ack_ids: ["2"], ack_deadline_seconds: 120
mock_subscription_admin.expect :modify_ack_deadline_internal, nil, subscription: subscription_path("my-sub"), ack_ids: ["2"], ack_deadline_seconds: 120


end
Expand Down Expand Up @@ -262,7 +263,7 @@ def mock_pubsub
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :acknowledge, nil, ["projects/my-project/subscriptions/my-ordered-topic-sub", ["2"], Hash]
mock_subscription_admin.expect :acknowledge_internal, nil, ["projects/my-project/subscriptions/my-ordered-topic-sub", ["2"], Hash]
end
end

Expand All @@ -276,7 +277,7 @@ def mock_pubsub
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :streaming_pull, [].to_enum, [Enumerator, Hash]
mock_subscription_admin.expect :acknowledge, nil, [Hash]
mock_subscription_admin.expect :acknowledge_internal, nil, [Hash]
end
end

Expand All @@ -286,28 +287,34 @@ def mock_pubsub
doctest.before "Google::Cloud::PubSub::Publisher" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_topic_admin.expect :get_topic, topic_resp, topic: topic_path("my-topic-only")
mock_topic_admin.expect :publish, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :publish_internal, OpenStruct.new(message_ids: ["1"]), [Hash]
end
end

doctest.before "Google::Cloud::PubSub::Publisher#reload!" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_topic_admin.expect :get_topic, topic_resp, topic: topic_path("my-topic")
end
end

doctest.before "Google::Cloud::PubSub::Publisher#async_publisher" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_topic_admin.expect :get_topic, topic_resp, topic: topic_path("my-topic")
mock_topic_admin.expect :publish, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :publish_internal, OpenStruct.new(message_ids: ["1"]), [Hash]
end
end

doctest.before "Google::Cloud::PubSub::Publisher#publish" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_topic_admin.expect :get_topic, topic_resp, topic: topic_path("my-topic")
mock_topic_admin.expect :publish, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :publish_internal, OpenStruct.new(message_ids: ["1"]), [Hash]
end
end

doctest.before "Google::Cloud::PubSub::Publisher#publish@Additionally, a message can be published with attributes:" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_topic_admin.expect :get_topic, topic_resp, topic: topic_path("my-topic")
mock_topic_admin.expect :publish, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :publish_internal, OpenStruct.new(message_ids: ["1"]), [Hash]
end
end

Expand All @@ -319,14 +326,14 @@ def mock_pubsub
pubsub_message("task 2 completed", { "foo" => "baz" }),
pubsub_message("task 3 completed", { "foo" => "bif" })
]
mock_topic_admin.expect :publish, OpenStruct.new(message_ids: ["1", "2", "3"]), [Hash]
mock_topic_admin.expect :publish_internal, OpenStruct.new(message_ids: ["1", "2", "3"]), [Hash]
end
end

doctest.before "Google::Cloud::PubSub::Publisher#publish@Ordered messages are supported using ordering_key:" do
mock_pubsub do |mock_topic_admin, mock_subscription_admin|
mock_topic_admin.expect :get_topic, topic_resp, topic: topic_path("my-ordered-topic")
mock_topic_admin.expect :publish, OpenStruct.new(message_ids: ["1"]), [Hash]
mock_topic_admin.expect :publish_internal, OpenStruct.new(message_ids: ["1"]), [Hash]
end
end

Expand All @@ -347,7 +354,7 @@ def mock_pubsub
pubsub_message("task 2 completed", { "foo" => "baz" }),
pubsub_message("task 3 completed", { "foo" => "bif" })
]
mock_topic_admin.expect :publish, OpenStruct.new(message_ids: ["1", "2", "3"]), [Hash]
mock_topic_admin.expect :publish_internal, OpenStruct.new(message_ids: ["1", "2", "3"]), [Hash]
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions google-cloud-storage/support/doctest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

require "minitest/focus"
require "minitest/mock"
require "ostruct"

require "google/cloud/storage"
require "google/cloud/pubsub"
Expand Down
2 changes: 2 additions & 0 deletions google-cloud-trace/support/doctest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
require "google/cloud/trace"
require "minitest/rg"
require "minitest/focus"
require "minitest/mock"
require "ostruct"
require "active_record"

module Google
Expand Down
Loading
Loading