aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby/spec/server_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'src/ruby/spec/server_spec.rb')
-rw-r--r--src/ruby/spec/server_spec.rb234
1 files changed, 141 insertions, 93 deletions
diff --git a/src/ruby/spec/server_spec.rb b/src/ruby/spec/server_spec.rb
index 598b7cfa7b..28f520a2f6 100644
--- a/src/ruby/spec/server_spec.rb
+++ b/src/ruby/spec/server_spec.rb
@@ -30,72 +30,84 @@
require 'grpc'
require 'port_picker'
-module GRPC
+def load_test_certs
+ test_root = File.join(File.dirname(__FILE__), 'testdata')
+ files = ['ca.pem', 'server1.key', 'server1.pem']
+ files.map { |f| File.open(File.join(test_root, f)).read }
+end
- describe Server do
+Server = GRPC::Core::Server
- before(:each) do
- @cq = CompletionQueue.new
- end
+describe Server do
- describe '#start' do
+ def create_test_cert
+ GRPC::Core::ServerCredentials.new(*load_test_certs)
+ end
- it 'runs without failing' do
- blk = Proc.new do
- s = Server.new(@cq, nil).start
- end
- expect(&blk).to_not raise_error
- end
+ before(:each) do
+ @cq = GRPC::Core::CompletionQueue.new
+ end
- it 'fails if the server is closed' do
- s = Server.new(@cq, nil)
- s.close
- expect { s.start }.to raise_error(RuntimeError)
+ describe '#start' do
+
+ it 'runs without failing' do
+ blk = Proc.new do
+ s = Server.new(@cq, nil).start
end
+ expect(&blk).to_not raise_error
+ end
+ it 'fails if the server is closed' do
+ s = Server.new(@cq, nil)
+ s.close
+ expect { s.start }.to raise_error(RuntimeError)
end
- describe '#destroy' do
- it 'destroys a server ok' do
- s = start_a_server
- blk = Proc.new { s.destroy }
- expect(&blk).to_not raise_error
- end
+ end
- it 'can be called more than once without error' do
- s = start_a_server
- begin
- blk = Proc.new { s.destroy }
- expect(&blk).to_not raise_error
- blk.call
- expect(&blk).to_not raise_error
- ensure
- s.close
- end
- end
+ describe '#destroy' do
+ it 'destroys a server ok' do
+ s = start_a_server
+ blk = Proc.new { s.destroy }
+ expect(&blk).to_not raise_error
end
- describe '#close' do
- it 'closes a server ok' do
- s = start_a_server
- begin
- blk = Proc.new { s.close }
- expect(&blk).to_not raise_error
- ensure
- s.close
- end
+ it 'can be called more than once without error' do
+ s = start_a_server
+ begin
+ blk = Proc.new { s.destroy }
+ expect(&blk).to_not raise_error
+ blk.call
+ expect(&blk).to_not raise_error
+ ensure
+ s.close
end
+ end
+ end
- it 'can be called more than once without error' do
- s = start_a_server
+ describe '#close' do
+ it 'closes a server ok' do
+ s = start_a_server
+ begin
blk = Proc.new { s.close }
expect(&blk).to_not raise_error
- blk.call
- expect(&blk).to_not raise_error
+ ensure
+ s.close
end
end
- describe '#add_http_port' do
+ it 'can be called more than once without error' do
+ s = start_a_server
+ blk = Proc.new { s.close }
+ expect(&blk).to_not raise_error
+ blk.call
+ expect(&blk).to_not raise_error
+ end
+ end
+
+ describe '#add_http_port' do
+
+ describe 'for insecure servers' do
it 'runs without failing' do
blk = Proc.new do
@@ -114,72 +126,108 @@ module GRPC
end
- describe '#new' do
+ describe 'for secure servers' do
- it 'takes a completion queue with nil channel args' do
- expect { Server.new(@cq, nil) }.to_not raise_error
+ it 'runs without failing' do
+ blk = Proc.new do
+ s = Server.new(@cq, nil)
+ s.add_http2_port('localhost:0', true)
+ s.close
+ end
+ expect(&blk).to_not raise_error
end
- it 'does not take a hash with bad keys as channel args' do
- blk = construct_with_args(Object.new => 1)
- expect(&blk).to raise_error TypeError
- blk = construct_with_args(1 => 1)
- expect(&blk).to raise_error TypeError
+ it 'fails if the server is closed' do
+ s = Server.new(@cq, nil)
+ s.close
+ blk = Proc.new { s.add_http2_port('localhost:0', true) }
+ expect(&blk).to raise_error(RuntimeError)
end
- it 'does not take a hash with bad values as channel args' do
- blk = construct_with_args(:symbol => Object.new)
- expect(&blk).to raise_error TypeError
- blk = construct_with_args('1' => Hash.new)
- expect(&blk).to raise_error TypeError
- end
+ end
- it 'can take a hash with a symbol key as channel args' do
- blk = construct_with_args(:a_symbol => 1)
- expect(&blk).to_not raise_error
- end
+ end
- it 'can take a hash with a string key as channel args' do
- blk = construct_with_args('a_symbol' => 1)
- expect(&blk).to_not raise_error
- end
+ shared_examples '#new' do
- it 'can take a hash with a string value as channel args' do
- blk = construct_with_args(:a_symbol => '1')
- expect(&blk).to_not raise_error
- end
+ it 'takes a completion queue with nil channel args' do
+ expect { Server.new(@cq, nil, create_test_cert) }.to_not raise_error
+ end
- it 'can take a hash with a symbol value as channel args' do
- blk = construct_with_args(:a_symbol => :another_symbol)
- expect(&blk).to_not raise_error
- end
+ it 'does not take a hash with bad keys as channel args' do
+ blk = construct_with_args(Object.new => 1)
+ expect(&blk).to raise_error TypeError
+ blk = construct_with_args(1 => 1)
+ expect(&blk).to raise_error TypeError
+ end
- it 'can take a hash with a numeric value as channel args' do
- blk = construct_with_args(:a_symbol => 1)
- expect(&blk).to_not raise_error
- end
+ it 'does not take a hash with bad values as channel args' do
+ blk = construct_with_args(:symbol => Object.new)
+ expect(&blk).to raise_error TypeError
+ blk = construct_with_args('1' => Hash.new)
+ expect(&blk).to raise_error TypeError
+ end
- it 'can take a hash with many args as channel args' do
- args = Hash[127.times.collect { |x| [x.to_s, x] } ]
- blk = construct_with_args(args)
- expect(&blk).to_not raise_error
- end
+ it 'can take a hash with a symbol key as channel args' do
+ blk = construct_with_args(:a_symbol => 1)
+ expect(&blk).to_not raise_error
+ end
+
+ it 'can take a hash with a string key as channel args' do
+ blk = construct_with_args('a_symbol' => 1)
+ expect(&blk).to_not raise_error
+ end
+ it 'can take a hash with a string value as channel args' do
+ blk = construct_with_args(:a_symbol => '1')
+ expect(&blk).to_not raise_error
end
+ it 'can take a hash with a symbol value as channel args' do
+ blk = construct_with_args(:a_symbol => :another_symbol)
+ expect(&blk).to_not raise_error
+ end
+
+ it 'can take a hash with a numeric value as channel args' do
+ blk = construct_with_args(:a_symbol => 1)
+ expect(&blk).to_not raise_error
+ end
+
+ it 'can take a hash with many args as channel args' do
+ args = Hash[127.times.collect { |x| [x.to_s, x] } ]
+ blk = construct_with_args(args)
+ expect(&blk).to_not raise_error
+ end
+
+ end
+
+ describe '#new with an insecure channel' do
+
def construct_with_args(a)
Proc.new { Server.new(@cq, a) }
end
- def start_a_server
- port = find_unused_tcp_port
- host = "localhost:#{port}"
- s = Server.new(@cq, nil)
- s.add_http2_port(host)
- s.start
- s
+ it_behaves_like '#new'
+
+ end
+
+ describe '#new with a secure channel' do
+
+ def construct_with_args(a)
+ Proc.new { Server.new(@cq, a, create_test_cert) }
end
+ it_behaves_like '#new'
+
+ end
+
+ def start_a_server
+ port = find_unused_tcp_port
+ host = "localhost:#{port}"
+ s = Server.new(@cq, nil)
+ s.add_http2_port(host)
+ s.start
+ s
end
end