<%- 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 client streaming method. <%- fields.each do |field| -%> <%= field.name %> = <%= field.default_value %> <%- end -%> <%= method.name %>_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:| assert_equal :<%= method.name %>, name assert_kind_of Enumerable, request refute_nil options request 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 enumerable object with hash and protobuf object. request_hash = { <%= fields.map(&:as_kwarg).join ", " %> } request_proto = <%= method.request_type %>.new <%= fields.map(&:as_kwarg).join ", " %> enum_input = [request_hash, request_proto].to_enum client.<%= method.name %> enum_input do |response, operation| <%= indent_tail render(partial: "service/test/method/assert_response", locals: { method: method }), 6 %> end # Use stream input object (from gapic-common). request_hash = { <%= fields.map(&:as_kwarg).join ", " %> } request_proto = <%= method.request_type %>.new <%= fields.map(&:as_kwarg).join ", " %> stream_input = Gapic::StreamInput.new client.<%= method.name %> stream_input do |response, operation| <%= indent_tail render(partial: "service/test/method/assert_response", locals: { method: method }), 6 %> end stream_input << request_hash stream_input << request_proto stream_input.close # Use enumerable object with hash and protobuf object with options. request_hash = { <%= fields.map(&:as_kwarg).join ", " %> } request_proto = <%= method.request_type %>.new <%= fields.map(&:as_kwarg).join ", " %> enum_input = [request_hash, request_proto].to_enum client.<%= method.name %> enum_input, grpc_options do |response, operation| <%= indent_tail render(partial: "service/test/method/assert_response", locals: { method: method }), 6 %> end # Use stream input object (from gapic-common) with options. request_hash = { <%= fields.map(&:as_kwarg).join ", " %> } request_proto = <%= method.request_type %>.new <%= fields.map(&:as_kwarg).join ", " %> stream_input = Gapic::StreamInput.new client.<%= method.name %> stream_input, grpc_options do |response, operation| <%= indent_tail render(partial: "service/test/method/assert_response", locals: { method: method }), 6 %> end stream_input << request_hash stream_input << request_proto stream_input.close # Verify method calls assert_equal 4, <%= method.name %>_client_stub.call_rpc_count <%= method.name %>_client_stub.requests.each do |request| request.to_a.each do |r| assert_kind_of <%= method.request_type %>, r <%- fields.each do |field| -%> <%- if field.message? && field.repeated? && !field.map? -%> assert_kind_of <%= field.type_name_full %>, r.<%= field.name %>.first <%- elsif field.map? -%> assert_equal(<%= field.default_value %>, r.<%= field.name %>.to_h) <%- elsif field.message? -%> assert_equal Gapic::Protobuf.coerce(<%= field.default_value %>, to: <%= field.type_name_full %>), r.<%= field.name %> <%- else -%> assert_equal <%= field.default_value %>, r.<%= field.name %> <%- end -%> <%- if field.oneof? && !field.proto3_optional? -%> assert_equal :<%= field.name %>, r.<%= field.oneof_name %> <%- end -%> <%- if field.proto3_optional? -%> assert r.has_<%= field.name %>? <%- end -%> <%- end -%> end end end end