Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Bump deps for warden-protocol
Browse files Browse the repository at this point in the history
- Get rspec working again

Signed-off-by: Michael Fraenkel <[email protected]>
  • Loading branch information
swetharepakula authored and Michael Fraenkel committed Jan 5, 2016
1 parent 634ebb2 commit 744a82a
Show file tree
Hide file tree
Showing 32 changed files with 455 additions and 259 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.7
2.2.4
3 changes: 3 additions & 0 deletions warden-protocol/lib/warden/protocol/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def safe
Beefcake::Message::InvalidValueError,
Beefcake::Message::RequiredFieldNotSetError => e
raise ProtocolError, e
rescue Exception => e
raise ProtocolError, e
end

def reload
Expand Down Expand Up @@ -151,4 +153,5 @@ def error?
end

require "warden/protocol/pb"
require "warden/protocol/pb_ext"
require "warden/protocol/message"
10 changes: 10 additions & 0 deletions warden-protocol/lib/warden/protocol/pb_ext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Warden
module Protocol

class SpawnRequest
def filtered_fields
[:script]
end
end
end
end
58 changes: 29 additions & 29 deletions warden-protocol/spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
request = Warden::Protocol::SpawnRequest.new(:handle => "blah",
:script => "script")
wrapped = request.wrap
wrapped.should be_an_instance_of(Warden::Protocol::Message)
wrapped.type.should == Warden::Protocol::SpawnRequest.type
expect(wrapped).to be_an_instance_of(Warden::Protocol::Message)
expect(wrapped.type).to eq(Warden::Protocol::SpawnRequest.type)
decoded = Warden::Protocol::SpawnRequest.decode(wrapped.payload)
decoded.handle.should == request.handle
decoded.script.should == request.script
expect(decoded.handle).to eq(request.handle)
expect(decoded.script).to eq(request.script)
end

it "should wrap beefcake errors" do
expect {
Warden::Protocol::SpawnRequest.new.wrap
}.to raise_error(Warden::Protocol::ProtocolError) { |e|
e.cause.class.name.should =~ /^Beefcake/
expect(e.cause.class.name).to match(/^Beefcake/)
}
end
end
Expand All @@ -28,17 +28,17 @@
it "should respond to #wrap" do
response = Warden::Protocol::SpawnResponse.new(:job_id => 1)
wrapped = response.wrap
wrapped.should be_an_instance_of(Warden::Protocol::Message)
wrapped.type.should == Warden::Protocol::SpawnResponse.type
expect(wrapped).to be_an_instance_of(Warden::Protocol::Message)
expect(wrapped.type).to eq(Warden::Protocol::SpawnResponse.type)
decoded = Warden::Protocol::SpawnResponse.decode(wrapped.payload)
decoded.job_id.should == response.job_id
expect(decoded.job_id).to eq(response.job_id)
end

it "should wrap beefcake errors" do
expect {
Warden::Protocol::SpawnResponse.new.wrap
}.to raise_error(Warden::Protocol::ProtocolError) { |e|
e.cause.class.name.should =~ /^Beefcake/
expect(e.cause.class.name).to match(/^Beefcake/)
}
end
end
Expand All @@ -49,16 +49,16 @@
w.type = Warden::Protocol::Message::Type::Spawn
w.payload = Warden::Protocol::SpawnRequest.new(:handle => "blah",
:script => "script").encode
w.should be_valid
expect(w).to be_valid

w.request.should be_a(Warden::Protocol::SpawnRequest)
expect(w.request).to be_a(Warden::Protocol::SpawnRequest)
end

it "should wrap beefcake errors" do
w = Warden::Protocol::Message.new
w.type = Warden::Protocol::Message::Type::Spawn
w.payload = "bad payload"
w.should be_valid
expect(w).to be_valid

expect { w.request }.to raise_error(Warden::Protocol::ProtocolError)
end
Expand All @@ -70,17 +70,17 @@
w.type = Warden::Protocol::Message::Type::Spawn
w.payload = Warden::Protocol::SpawnResponse.new(:handle => "blah",
:job_id => 2).encode
w.should be_valid
expect(w).to be_valid

w.response.should be_a(Warden::Protocol::SpawnResponse)
expect(w.response).to be_a(Warden::Protocol::SpawnResponse)
end

it "should wrap beefcake errors" do
w = Warden::Protocol::Message.new
w.type = Warden::Protocol::Message::Type::Spawn
w.payload = "bad payload"

w.should be_valid
expect(w).to be_valid

expect { w.response }.to raise_error(Warden::Protocol::ProtocolError)
end
Expand All @@ -96,54 +96,54 @@ module Test

describe "#protocol_type_to_str" do
it "should return string representation of constants in a module" do
described_class.protocol_type_to_str(Test).should == "A, B"
expect(described_class.protocol_type_to_str(Test)).to eq("A, B")
end

it "should return string representation of symbol" do
described_class.protocol_type_to_str(:test).should == "test"
expect(described_class.protocol_type_to_str(:test)).to eq("test")
end

it "should return nil for invalid parameter" do
described_class.protocol_type_to_str(123).should be_nil
expect(described_class.protocol_type_to_str(123)).to be_nil
end
end

describe "#to_ruby_type" do
it "should use the type converter if is defined" do
Warden::Protocol::TypeConverter.should_receive("[]").once.
allow(Warden::Protocol::TypeConverter).to receive("[]").once.
with(:uint32).and_return(lambda { |arg| Integer(arg) } )

described_class.to_ruby_type("123", :uint32).should == 123
expect(described_class.to_ruby_type("123", :uint32)).to eq(123)
end

it "should return value of constant defined in the module" do
Warden::Protocol::TypeConverter.should_receive("[]").once.
allow(Warden::Protocol::TypeConverter).to receive("[]").once.
with(Test).and_return(nil)

described_class.to_ruby_type("A", Test).should == 1
expect(described_class.to_ruby_type("A", Test)).to eq(1)
end

it "should raise an error if a constant is not defined in a module" do
Warden::Protocol::TypeConverter.should_receive("[]").once.
allow(Warden::Protocol::TypeConverter).to receive("[]").once.
with(Test).and_return(nil)

expect {
described_class.to_ruby_type("D", Test)
}.to raise_error { |error|
error.should be_an_instance_of TypeError
error.message.should == "The constant: 'D' is not defined in the module: 'Test'."
expect(error).to be_an_instance_of TypeError
expect(error.message).to eq("The constant: 'D' is not defined in the module: 'Test'.")
}
end

it "should raise an error if protocol type is not a module and no type converter is defined" do
Warden::Protocol::TypeConverter.should_receive("[]").once.
allow(Warden::Protocol::TypeConverter).to receive("[]").once.
with(:test).and_return(nil)

expect {
described_class.to_ruby_type("test", :test)
}.to raise_error { |error|
error.should be_an_instance_of TypeError
error.message.should == "Non-existent protocol type passed: 'test'."
expect(error).to be_an_instance_of TypeError
expect(error.message).to eq("Non-existent protocol type passed: 'test'.")
}
end
end
Expand All @@ -167,4 +167,4 @@ def filtered_fields
expect(message.filtered_hash.keys).to_not include(:field2)
end
end
end
end
16 changes: 8 additions & 8 deletions warden-protocol/spec/buffer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
it "should support iterating over requests" do
subject << Warden::Protocol::Buffer.request_to_wire(request)
subject.each_request do |request|
request.class.should == Warden::Protocol::EchoRequest
request.message.should == "request"
expect(request.class).to eq(Warden::Protocol::EchoRequest)
expect(request.message).to eq("request")
end
end

it "should support iterating over responses" do
subject << Warden::Protocol::Buffer.response_to_wire(response)
subject.each_response do |response|
response.class.should == Warden::Protocol::EchoResponse
response.message.should == "response"
expect(response.class).to eq(Warden::Protocol::EchoResponse)
expect(response.message).to eq("response")
end
end

Expand All @@ -40,8 +40,8 @@
end

subject.each_request do |request|
request.class.should == Warden::Protocol::EchoRequest
request.message.should == "request"
expect(request.class).to eq(Warden::Protocol::EchoRequest)
expect(request.message).to eq("request")
end
end

Expand All @@ -59,8 +59,8 @@
end

subject.each_response do |response|
response.class.should == Warden::Protocol::EchoResponse
response.message.should == "response"
expect(response.class).to eq(Warden::Protocol::EchoResponse)
expect(response.message).to eq("response")
end
end
end
Expand Down
27 changes: 18 additions & 9 deletions warden-protocol/spec/copy_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe Warden::Protocol::CopyInRequest do
subject(:request) do
described_class.new(
Warden::Protocol::CopyInRequest.new(
:handle => "handle",
:src_path => "/src",
:dst_path => "/dst"
Expand All @@ -13,8 +13,10 @@

it_should_behave_like "wrappable request"

its("class.type_camelized") { should == "CopyIn" }
its("class.type_underscored") { should == "copy_in" }
it 'has class type methods' do
expect(request.class.type_camelized).to eq('CopyIn')
expect(request.class.type_underscored).to eq('copy_in')
end

field :handle do
it_should_be_required
Expand All @@ -32,20 +34,27 @@
end

it "should respond to #create_response" do
request.create_response.should be_a(Warden::Protocol::CopyInResponse)
expect(request.create_response).to be_a(Warden::Protocol::CopyInResponse)
end
end

describe Warden::Protocol::CopyInResponse do
subject(:response) do
described_class.new
Warden::Protocol::CopyInResponse.new
end

it_should_behave_like "wrappable response"

its("class.type_camelized") { should == "CopyIn" }
its("class.type_underscored") { should == "copy_in" }
it 'has class type methods' do
expect(response.class.type_camelized).to eq('CopyIn')
expect(response.class.type_underscored).to eq('copy_in')
end

it { should be_ok }
it { should_not be_error }
it 'should be ok' do
expect(response).to be_ok
end

it 'should not be an error' do
expect(response).to_not be_error
end
end
27 changes: 18 additions & 9 deletions warden-protocol/spec/copy_out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe Warden::Protocol::CopyOutRequest do
subject(:request) do
described_class.new(
Warden::Protocol::CopyOutRequest.new(
:handle => "handle",
:src_path => "/src",
:dst_path => "/dst"
Expand All @@ -13,8 +13,10 @@

it_should_behave_like "wrappable request"

its("class.type_camelized") { should == "CopyOut" }
its("class.type_underscored") { should == "copy_out" }
it 'has class type methods' do
expect(request.class.type_camelized).to eq('CopyOut')
expect(request.class.type_underscored).to eq('copy_out')
end

field :handle do
it_should_be_required
Expand All @@ -37,20 +39,27 @@
end

it "should respond to #create_response" do
request.create_response.should be_a(Warden::Protocol::CopyOutResponse)
expect(request.create_response).to be_a(Warden::Protocol::CopyOutResponse)
end
end

describe Warden::Protocol::CopyOutResponse do
subject(:response) do
described_class.new
Warden::Protocol::CopyOutResponse.new
end

it_should_behave_like "wrappable response"

its("class.type_camelized") { should == "CopyOut" }
its("class.type_underscored") { should == "copy_out" }
it 'has class type methods' do
expect(response.class.type_camelized).to eq('CopyOut')
expect(response.class.type_underscored).to eq('copy_out')
end

it { should be_ok }
it { should_not be_error }
it 'should be ok' do
expect(response).to be_ok
end

it 'should not be an error' do
expect(response).to_not be_error
end
end
Loading

0 comments on commit 744a82a

Please sign in to comment.