<%- 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 unary 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 <%= 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 -%> <%- 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| <%= indent_tail render(partial: "service/test/method/assert_response", locals: { method: method }), 6 %> end <%- if fields.any? -%> # Use named arguments client.<%= method.name %> <%= fields.map(&:as_kwarg).join ", " %> do |response, operation| <%= indent_tail render(partial: "service/test/method/assert_response", locals: { method: method }), 6 %> end <%- end -%> # Use protobuf object client.<%= method.name %> <%= method.request_type %>.new(<%= fields.map(&:as_kwarg).join ", " %>) do |response, operation| <%= indent_tail render(partial: "service/test/method/assert_response", locals: { method: method }), 6 %> end # Use hash object with options client.<%= method.name %>({ <%= fields.map(&:as_kwarg).join ", " %> }, grpc_options) do |response, operation| <%= indent_tail render(partial: "service/test/method/assert_response", locals: { method: method }), 6 %> end # Use protobuf object with options client.<%= method.name %> <%= method.request_type %>.new(<%= fields.map(&:as_kwarg).join ", " %>), grpc_options do |response, operation| <%= indent_tail render(partial: "service/test/method/assert_response", locals: { method: method }), 6 %> end # Verify method calls assert_equal <%= fields.any? ? 5 : 4 %>, <%= method.name %>_client_stub.call_rpc_count end end