Module: Gritz::Testing::RpcHelper

Included in:
Minitest
Defined in:
/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/testing/rpc_helper.rb

Overview

Controller tests exercise the real dispatcher without opening a socket.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_rpc_call ⇒ Object (readonly)



10
11
12
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/testing/rpc_helper.rb', line 10

def last_rpc_call
  @last_rpc_call
end

Instance Method Details

#rpc(action, messages, controller: nil, metadata: {}, deadline: nil, peer: nil, peer_identity: nil, middleware: true, logger: Logger.new(File::NULL)) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/testing/rpc_helper.rb', line 12

def rpc(action, messages, controller: nil, metadata: {}, deadline: nil, peer: nil, peer_identity: nil,
        middleware: true, logger: Logger.new(File::NULL))
  controller ||= described_class if respond_to?(:described_class)
  raise ArgumentError, "pass controller: or use an RSpec controller example group" unless controller

  router = Router.new(controllers: [controller], logger:)
  descriptor = router.routes.values.find { |route| route.action == action.to_sym || route.name == action.to_s }
  raise ArgumentError, "unknown RPC action: #{action}" unless descriptor

  input = descriptor.client_streaming? ? messages : [messages]
  @last_rpc_call = InMemoryCall.new(method_descriptor: descriptor, messages: input, metadata:, deadline:, peer:, peer_identity:)
  stack = middleware == true ? Middleware::Stack.default : middleware
  result = Dispatcher.new(router:, middleware: stack, logger:).call(@last_rpc_call)
  descriptor.server_streaming? ? @last_rpc_call.responses : result
end