Add spec to make sure invalid metadata values raise ArgumentError

pull/5528/head
Rafael Sales 9 years ago
parent ac491d8c1f
commit bc846f72d6
  1. 35
      src/ruby/spec/generic/client_stub_spec.rb

@ -193,44 +193,45 @@ describe 'ClientStub' do
describe '#client_streamer' do describe '#client_streamer' do
shared_examples 'client streaming' do shared_examples 'client streaming' do
before(:each) do before(:each) do
server_port = create_test_server
host = "localhost:#{server_port}"
@stub = GRPC::ClientStub.new(host, @cq, :this_channel_is_insecure)
@options = { k1: 'v1', k2: 'v2' }
@sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s } @sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s }
@resp = 'a_reply' @resp = 'a_reply'
end end
it 'should send requests to/receive a reply from a server' do it 'should send requests to/receive a reply from a server' do
server_port = create_test_server
host = "localhost:#{server_port}"
th = run_client_streamer(@sent_msgs, @resp, @pass) th = run_client_streamer(@sent_msgs, @resp, @pass)
stub = GRPC::ClientStub.new(host, @cq, :this_channel_is_insecure) expect(get_response(@stub)).to eq(@resp)
expect(get_response(stub)).to eq(@resp)
th.join th.join
end end
it 'should send metadata to the server ok' do it 'should send metadata to the server ok' do
server_port = create_test_server th = run_client_streamer(@sent_msgs, @resp, @pass, @options)
host = "localhost:#{server_port}" expect(get_response(@stub)).to eq(@resp)
th = run_client_streamer(@sent_msgs, @resp, @pass,
k1: 'v1', k2: 'v2')
stub = GRPC::ClientStub.new(host, @cq, :this_channel_is_insecure)
expect(get_response(stub)).to eq(@resp)
th.join th.join
end end
it 'should raise an error if the status is not ok' do it 'should raise an error if the status is not ok' do
server_port = create_test_server
host = "localhost:#{server_port}"
th = run_client_streamer(@sent_msgs, @resp, @fail) th = run_client_streamer(@sent_msgs, @resp, @fail)
stub = GRPC::ClientStub.new(host, @cq, :this_channel_is_insecure) blk = proc { get_response(@stub) }
blk = proc { get_response(stub) }
expect(&blk).to raise_error(GRPC::BadStatus) expect(&blk).to raise_error(GRPC::BadStatus)
th.join th.join
end end
it 'should raise ArgumentError if metadata contains invalid values' do
@options.merge!(k3: 3)
expect do
get_response(@stub)
end.to raise_error(ArgumentError,
/Header values must be of type string or array/)
end
end end
describe 'without a call operation' do describe 'without a call operation' do
def get_response(stub) def get_response(stub)
stub.client_streamer(@method, @sent_msgs, noop, noop, stub.client_streamer(@method, @sent_msgs, noop, noop, @options)
k1: 'v1', k2: 'v2')
end end
it_behaves_like 'client streaming' it_behaves_like 'client streaming'
@ -239,7 +240,7 @@ describe 'ClientStub' do
describe 'via a call operation' do describe 'via a call operation' do
def get_response(stub) def get_response(stub)
op = stub.client_streamer(@method, @sent_msgs, noop, noop, op = stub.client_streamer(@method, @sent_msgs, noop, noop,
return_op: true, k1: 'v1', k2: 'v2') @options.merge(return_op: true))
expect(op).to be_a(GRPC::ActiveCall::Operation) expect(op).to be_a(GRPC::ActiveCall::Operation)
op.execute op.execute
end end

Loading…
Cancel
Save