<%- assert_locals method -%> <%- full_client_name = defined?(client_name_full) ? client_name_full : method.service.client_name_full -%> <%- fields = method.fields_with_first_oneof -%> def test_<%= method.name %> # Create GRPC objects. grpc_response = <%= method.return_type %>.new grpc_operation = GRPC::ActiveCall::Operation.new nil grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure grpc_options = {} # Create request parameters for a server streaming method. <%- fields.each do |field| -%> <%= field.name %> = <%= field.default_value %> <%- end -%> <%= method.name %>_client_stub = ClientStub.new [grpc_response].to_enum, grpc_operation do |name, request, options:| assert_equal :<%= method.name %>, name assert_kind_of <%= method.request_type %>, request <%- fields.each do |field| -%> <%- if field.message? && field.repeated? && !field.map? -%> assert_kind_of <%= field.type_name_full %>, request["<%= field.name %>"].first <%- elsif field.map? -%> assert_equal(<%= field.default_value %>, request["<%= field.name %>"].to_h) <%- elsif field.message? -%> assert_equal Gapic::Protobuf.coerce(<%= field.default_value %>, to: <%= field.type_name_full %>), request["<%= field.name %>"] <%- else -%> assert_equal <%= field.default_value %>, request["<%= field.name %>"] <%- end -%> <%- if field.oneof? && !field.proto3_optional? -%> assert_equal :<%= field.name %>, request.<%= field.oneof_name %> <%- end -%> <%- if field.proto3_optional? -%> assert request.has_<%= field.name %>? <%- end -%> <%- end -%> refute_nil options end Gapic::ServiceStub.stub :new, <%= method.name %>_client_stub do # Create client client = <%= full_client_name %>.new do |config| config.credentials = grpc_channel end # Use hash object client.<%= method.name %>({ <%= fields.map(&:as_kwarg).join ", " %> }) do |response, operation| assert_kind_of Enumerable, response response.to_a.each do |r| assert_kind_of <%= method.return_type %>, r end assert_equal grpc_operation, operation end # Use named arguments client.<%= method.name %> <%= fields.map(&:as_kwarg).join ", " %> do |response, operation| assert_kind_of Enumerable, response response.to_a.each do |r| assert_kind_of <%= method.return_type %>, r end assert_equal grpc_operation, operation end # Use protobuf object client.<%= method.name %> <%= method.request_type %>.new(<%= fields.map(&:as_kwarg).join ", " %>) do |response, operation| assert_kind_of Enumerable, response response.to_a.each do |r| assert_kind_of <%= method.return_type %>, r end assert_equal grpc_operation, operation end # Use hash object with options client.<%= method.name %>({ <%= fields.map(&:as_kwarg).join ", " %> }, grpc_options) do |response, operation| assert_kind_of Enumerable, response response.to_a.each do |r| assert_kind_of <%= method.return_type %>, r end assert_equal grpc_operation, operation end # Use protobuf object with options client.<%= method.name %>(<%= method.request_type %>.new(<%= fields.map(&:as_kwarg).join ", " %>), grpc_options) do |response, operation| assert_kind_of Enumerable, response response.to_a.each do |r| assert_kind_of <%= method.return_type %>, r end assert_equal grpc_operation, operation end # Verify method calls assert_equal 5, <%= method.name %>_client_stub.call_rpc_count end end