Skip to content

Commit

Permalink
tests for services and rpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev committed Aug 14, 2013
1 parent 0f1f91b commit 6f8e3b1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/protocol_buffers/runtime/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.rpcs
def self.rpc(name, proto_name, request_type, response_type)
@rpcs ||= Array.new
@rpcs = @rpcs.dup
@rpcs << Rpc.new(name.to_sym, proto_name, request_type, response_type, self)
@rpcs << Rpc.new(name.to_sym, proto_name, request_type, response_type, self).freeze
@rpcs.freeze
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/proto_files/services.pb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class BarResponse < ::ProtocolBuffers::Message
class FooBarService < ::ProtocolBuffers::Service
set_fully_qualified_name "services.FooBarService"

rpc :get_foo, "GetFoo", ::Services::FooRequest, ::Services::FooResponse
rpc :get_bar, "GetBar", ::Services::BarRequest, ::Services::BarResponse
end
class NoNameFooBarService < ::ProtocolBuffers::Service
# purposefully removing qualified name to make sure that nothing breaks
#set_fully_qualified_name "services.NoNameFooBarService"

rpc :get_foo, "GetFoo", ::Services::FooRequest, ::Services::FooResponse
rpc :get_bar, "GetBar", ::Services::BarRequest, ::Services::BarResponse
end
Expand Down
5 changes: 5 additions & 0 deletions spec/proto_files/services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ service FooBarService {
rpc GetFoo(FooRequest) returns (FooResponse);
rpc GetBar(BarRequest) returns (BarResponse);
}

service NoNameFooBarService {
rpc GetFoo(FooRequest) returns (FooResponse);
rpc GetBar(BarRequest) returns (BarResponse);
}
49 changes: 47 additions & 2 deletions spec/runtime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
describe ProtocolBuffers, "runtime" do
before(:each) do
# clear our namespaces
%w( Simple Featureful Foo Packed TehUnknown TehUnknown2 TehUnknown3 Enums A C).each do |klass|
%w( Simple Featureful Foo Packed TehUnknown TehUnknown2 TehUnknown3 Enums A C Services).each do |klass|
Object.send(:remove_const, klass.to_sym) if Object.const_defined?(klass.to_sym)
end

# load test protos
%w( simple featureful packed enums no_package).each do |proto|
%w( simple featureful packed enums no_package services).each do |proto|
load File.join(File.dirname(__FILE__), "proto_files", "#{proto}.pb.rb")
end
end
Expand Down Expand Up @@ -800,4 +800,49 @@ class IntMsg < ProtocolBuffers::Message
Enums::FooMessage::NestedBarEnum.fully_qualified_name.should == nil
end

it "correctly handles service definitions" do
Services::FooBarService.rpcs.size.should == 2
get_foo_rpc = Services::FooBarService.rpcs[0]
get_bar_rpc = Services::FooBarService.rpcs[1]

get_foo_rpc.name.should == :get_foo
get_foo_rpc.proto_name.should == "GetFoo"
get_foo_rpc.request_class.should == Services::FooRequest
get_foo_rpc.response_class.should == Services::FooResponse
get_foo_rpc.service_class.should == Services::FooBarService

get_bar_rpc.name.should == :get_bar
get_bar_rpc.proto_name.should == "GetBar"
get_bar_rpc.request_class.should == Services::BarRequest
get_bar_rpc.response_class.should == Services::BarResponse
get_bar_rpc.service_class.should == Services::FooBarService
end

it "correctly handles == for Rpcs" do
Services::FooBarService.rpcs.size.should == 2
get_foo_rpc = Services::FooBarService.rpcs[0]
get_bar_rpc = Services::FooBarService.rpcs[1]

get_foo_rpc.should == get_foo_rpc
get_bar_rpc.should == get_bar_rpc
get_foo_rpc.should_not == get_bar_rpc
end

it "correctly freezes rpcs" do
Services::FooBarService.rpcs.size.should == 2
get_foo_rpc = Services::FooBarService.rpcs[0]
get_bar_rpc = Services::FooBarService.rpcs[1]

get_foo_rpc.frozen?.should == true
get_bar_rpc.frozen?.should == true
get_foo_rpc.proto_name.frozen?.should == true
get_bar_rpc.proto_name.frozen?.should == true

Services::FooBarService.rpcs.frozen?.should == true
end

it "correctly handles fully qualified names on Services" do
Services::FooBarService.fully_qualified_name.should == "services.FooBarService"
Services::NoNameFooBarService.fully_qualified_name.should == nil
end
end

0 comments on commit 6f8e3b1

Please sign in to comment.