Skip to content

Commit

Permalink
Merge pull request #6 from muneebaahmad/include-metadata
Browse files Browse the repository at this point in the history
Add ability to include metadata in rpc calls.
  • Loading branch information
splittingred authored Oct 28, 2019
2 parents 1ee8dac + 746c851 commit facf74e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Note that this gem requires at least Gruf 2.5.1+ and RSpec 3.8+.
## Usage

* Add a test for a Gruf controller in `spec/rpc`
* Run the `run_rpc` method with two args: The gRPC method name, and the request object
* Run the `run_rpc` method with three args: The gRPC method name, the request object
and the active_call_options. The third argument is optional.
* Validate the response

## Example
Expand All @@ -46,9 +47,12 @@ To test it, you'd create `spec/rpc/thing_controller_spec.rb`:
describe ThingController do
describe '.get_thing' do
let(:request_proto) { Rpc::GetThingRequest.new(id: rand(1..100)) }

subject { run_rpc(:GetThing, request_proto) }

let(:metadata) {
{ 'user_id' => 'axj42i' }
}

subject { run_rpc(:GetThing, request_proto, active_call_options: { metadata: metadata }) }

it 'will return the thing' do
expect(subject).to be_a(Rpc::GetThingResponse)
expect(subject.id).to eq request_proto.id
Expand Down
4 changes: 2 additions & 2 deletions lib/gruf/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ module Rspec
end

config.before(:each, type: :gruf_controller) do
define_singleton_method :run_rpc do |method_name, request, &block|
define_singleton_method :run_rpc do |method_name, request, active_call_options: {}, &block|
@gruf_controller = described_class.new(
method_key: method_name.to_s.underscore.to_sym,
service: grpc_bound_service,
rpc_desc: grpc_bound_service.rpc_descs[method_name.to_sym],
active_call: grpc_active_call,
active_call: grpc_active_call(active_call_options),
message: request
)
resp = @gruf_controller.call(@gruf_controller.request.method_key)
Expand Down

0 comments on commit facf74e

Please sign in to comment.