From 4d9d4324ceaf4d110c04efec969ad168e9a11513 Mon Sep 17 00:00:00 2001 From: Sandy Cash Date: Fri, 8 Jan 2016 11:20:31 -0500 Subject: [PATCH] Update warden with latest dependencies Bump everything Signed-off-by: Michael Fraenkel --- warden/Gemfile | 8 +- warden/Gemfile.lock | 79 +++-- warden/spec/container/base_spec.rb | 128 +++---- warden/spec/container/features/quota_spec.rb | 50 +-- warden/spec/container/insecure_spec.rb | 6 +- warden/spec/container/linux_nested_spec.rb | 8 +- warden/spec/container/linux_spec.rb | 313 +++++++++--------- warden/spec/health_check_spec.rb | 4 +- warden/spec/mount_point_spec.rb | 28 +- warden/spec/network_spec.rb | 30 +- warden/spec/pool/base_spec.rb | 22 +- warden/spec/pool/network_spec.rb | 22 +- warden/spec/pool/port_spec.rb | 4 +- warden/spec/pool/uid_spec.rb | 8 +- warden/spec/repl/commands_manager_spec.rb | 266 +++++++-------- warden/spec/repl/repl_v2_runner_spec.rb | 46 +-- warden/spec/repl/repl_v2_spec.rb | 150 +++++---- warden/spec/spec_helper.rb | 2 +- warden/spec/support/examples/drain.rb | 52 +-- warden/spec/support/examples/file_transfer.rb | 42 +-- warden/spec/support/examples/info.rb | 4 +- warden/spec/support/examples/lifecycle.rb | 30 +- .../spec/support/examples/running_commands.rb | 78 ++--- warden/spec/support/examples/snapshotting.rb | 40 +-- warden/spec/support/helpers/drain.rb | 11 +- 25 files changed, 716 insertions(+), 715 deletions(-) diff --git a/warden/Gemfile b/warden/Gemfile index 11739640..f39aef35 100644 --- a/warden/Gemfile +++ b/warden/Gemfile @@ -1,10 +1,10 @@ source "http://rubygems.org" gem "rake" -gem "steno", "~> 0.0.15", :git => 'https://github.com/cloudfoundry/steno.git' +gem "steno", :git => 'https://github.com/cloudfoundry/steno.git' gem "membrane", :git => 'https://github.com/cloudfoundry/membrane.git' -gem "eventmachine", "1.0.3" -gem "em-posix-spawn", :git => 'https://github.com/cloudfoundry/common.git' +gem "eventmachine", "~> 1.0" +gem "em-posix-spawn", :path => '../em-posix-spawn' gem "yajl-ruby" gem "pidfile" @@ -12,5 +12,5 @@ gem "warden-protocol", :path => "../warden-protocol" gem "warden-client", :path => "../warden-client" group :spec do - gem "rspec", "~> 2.11.0" + gem "rspec", "~> 3.0" end diff --git a/warden/Gemfile.lock b/warden/Gemfile.lock index 36f5f4f3..2c7da2ed 100644 --- a/warden/Gemfile.lock +++ b/warden/Gemfile.lock @@ -1,24 +1,23 @@ -GIT - remote: https://github.com/cloudfoundry/common.git - revision: 6554ce1c83b73a945855bcbb18fbb3b1602a1a5a - specs: - em-posix-spawn (0.1.10) - eventmachine - posix-spawn - GIT remote: https://github.com/cloudfoundry/membrane.git - revision: b33b45c7b8a89af2b40aae1e1cb16e394877681f + revision: 1eeadcf64c20d94e61379707c20b16d3d9a26d87 specs: - membrane (0.0.3) + membrane (1.1.0) GIT remote: https://github.com/cloudfoundry/steno.git - revision: e71a658f05b7cbf54006c3cc29db752cdfb192df + revision: e0e7bb5cff8430e205f677ade927d4e488ebee10 specs: - steno (0.0.15) - grape - yajl-ruby + steno (1.2.4) + fluent-logger + yajl-ruby (~> 1.0) + +PATH + remote: ../em-posix-spawn + specs: + em-posix-spawn (0.1.10) + eventmachine + posix-spawn PATH remote: ../warden-client @@ -36,31 +35,27 @@ GEM remote: http://rubygems.org/ specs: beefcake (1.0.0) - diff-lcs (1.1.3) - eventmachine (1.0.3) - grape (0.2.1) - hashie (~> 1.2) - multi_json - multi_xml - rack - rack-mount - hashie (1.2.0) - multi_json (1.3.6) - multi_xml (0.5.1) + diff-lcs (1.2.5) + eventmachine (1.0.8) + fluent-logger (0.5.1) + msgpack (>= 0.4.4, < 0.6.0, != 0.5.3, != 0.5.2, != 0.5.1, != 0.5.0) + msgpack (0.5.12) pidfile (0.3.0) - posix-spawn (0.3.6) - rack (1.4.1) - rack-mount (0.8.3) - rack (>= 1.0.0) - rake (0.9.2.2) - rspec (2.11.0) - rspec-core (~> 2.11.0) - rspec-expectations (~> 2.11.0) - rspec-mocks (~> 2.11.0) - rspec-core (2.11.0) - rspec-expectations (2.11.1) - diff-lcs (~> 1.1.3) - rspec-mocks (2.11.1) + posix-spawn (0.3.11) + rake (10.4.2) + rspec (3.4.0) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-core (3.4.1) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-mocks (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) yajl-ruby (1.2.1) PLATFORMS @@ -68,15 +63,15 @@ PLATFORMS DEPENDENCIES em-posix-spawn! - eventmachine (= 1.0.3) + eventmachine (~> 1.0) membrane! pidfile rake - rspec (~> 2.11.0) - steno (~> 0.0.15)! + rspec (~> 3.0) + steno! warden-client! warden-protocol! yajl-ruby BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/warden/spec/container/base_spec.rb b/warden/spec/container/base_spec.rb index 4490b2c6..3bcffdde 100644 --- a/warden/spec/container/base_spec.rb +++ b/warden/spec/container/base_spec.rb @@ -50,12 +50,12 @@ def new_connection def initialize_container container = Container.new - container.stub(:do_create) - container.stub(:do_stop) - container.stub(:do_destroy) - container.stub(:do_info) - container.stub(:delete_snapshot) - container.stub(:write_snapshot) + allow(container).to receive(:do_create) + allow(container).to receive(:do_stop) + allow(container).to receive(:do_destroy) + allow(container).to receive(:do_info) + allow(container).to receive(:delete_snapshot) + allow(container).to receive(:write_snapshot) container.acquire container end @@ -64,53 +64,53 @@ def initialize_container let(:container) { Container.new } before do - container.stub(:delete_snapshot) - container.stub(:write_snapshot) + allow(container).to receive(:delete_snapshot) + allow(container).to receive(:write_snapshot) end context "on success" do before do - container.stub(:do_create) - container.should_receive(:write_snapshot) + allow(container).to receive(:do_create) + allow(container).to receive(:write_snapshot) end it "should call #do_create" do - container.should_receive(:do_create) + allow(container).to receive(:do_create) container.dispatch(Warden::Protocol::CreateRequest.new) end it "should return the container handle" do response = container.dispatch(Warden::Protocol::CreateRequest.new) - response.handle.should_not be_nil + expect(response.handle).to_not be_nil end it "should acquire a network" do container.dispatch(Warden::Protocol::CreateRequest.new) - container.network.should == network - network_pool.should be_empty + expect(container.network).to eq(network) + expect(network_pool).to be_empty end it "should acquire a uid" do container.dispatch(Warden::Protocol::CreateRequest.new) - container.uid.should == uid - uid_pool.should be_empty + expect(container.uid).to eq(uid) + expect(uid_pool).to be_empty end it "should register with the global registry" do container.dispatch(Warden::Protocol::CreateRequest.new) - Container.registry.size.should == 1 + expect(Container.registry.size).to eq(1) end end context "on failure" do before do - container.stub(:do_stop) - container.stub(:do_destroy) - container.stub(:do_create).and_raise(Warden::WardenError.new("create")) + allow(container).to receive(:do_stop) + allow(container).to receive(:do_destroy) + allow(container).to receive(:do_create).and_raise(Warden::WardenError.new("create")) end it "should destroy" do - container.should_receive(:do_destroy) + allow(container).to receive(:do_destroy) expect do container.dispatch(Warden::Protocol::CreateRequest.new) @@ -122,7 +122,7 @@ def initialize_container container.dispatch(Warden::Protocol::CreateRequest.new) end.to raise_error(Warden::WardenError, "create") - Container.registry.should be_empty + expect(Container.registry).to be_empty end it "should release the acquired network" do @@ -130,7 +130,7 @@ def initialize_container container.dispatch(Warden::Protocol::CreateRequest.new) end.to raise_error(Warden::WardenError, "create") - network_pool.size.should == 1 + expect(network_pool.size).to eq(1) end it "should release the acquired uid" do @@ -138,12 +138,12 @@ def initialize_container container.dispatch(Warden::Protocol::CreateRequest.new) end.to raise_error(Warden::WardenError, "create") - uid_pool.size.should == 1 + expect(uid_pool.size).to eq(1) end context "on failure of destroy" do before do - container.stub(:do_destroy).and_raise(Warden::WardenError.new("destroy")) + allow(container).to receive(:do_destroy).and_raise(Warden::WardenError.new("destroy")) end it "should raise original error" do @@ -157,7 +157,7 @@ def initialize_container container.dispatch(Warden::Protocol::CreateRequest.new) end.to raise_error(Warden::WardenError, "create") - network_pool.size.should == 1 + expect(network_pool.size).to eq(1) end it "should release the acquired uid" do @@ -165,7 +165,7 @@ def initialize_container container.dispatch(Warden::Protocol::CreateRequest.new) end.to raise_error(Warden::WardenError, "create") - uid_pool.size.should == 1 + expect(uid_pool.size).to eq(1) end end end @@ -179,23 +179,23 @@ def initialize_container subject(:container) { Container.new } before do - container.stub(:logger).and_return(logger) - container.stub(:hook) + allow(container).to receive(:logger).and_return(logger) + allow(container).to receive(:hook) end it "logs to debug level to avoid logging sensitive information in production" do - logger.should_receive(:debug).with(an_instance_of(String), request: request.filtered_hash, response: an_instance_of(Hash)) + allow(logger).to receive(:debug).with(an_instance_of(String), request: request.filtered_hash, response: an_instance_of(Hash)) container.dispatch(request) end it "calls filtered hash on the request to exclude sensitive information" do - request.should_receive(:filtered_hash) + allow(request).to receive(:filtered_hash) container.dispatch(request) end it "calls filtered hash on the response to exclude sensitive information" do - response.should_receive(:filtered_hash) + allow(response).to receive(:filtered_hash) container.dispatch(request) end end @@ -207,8 +207,8 @@ def initialize_container end it "should call #do_stop" do - @container.should_receive(:do_stop) - @container.should_receive(:write_snapshot) + allow(@container).to receive(:do_stop) + allow(@container).to receive(:write_snapshot) @container.dispatch(Warden::Protocol::StopRequest.new) end end @@ -220,7 +220,7 @@ def initialize_container end it "should call #do_destroy" do - @container.should_receive(:do_destroy) + allow(@container).to receive(:do_destroy) @container.dispatch(Warden::Protocol::DestroyRequest.new) end @@ -228,8 +228,8 @@ def initialize_container it "saves the container info as #obituary" do info_response = Warden::Protocol::InfoResponse.new - @container.should_receive(:do_stop) - @container.should_receive(:do_info).and_return(info_response) + allow(@container).to receive(:do_stop) + allow(@container).to receive(:do_info).and_return(info_response) expect do @container.dispatch(Warden::Protocol::DestroyRequest.new) @@ -238,7 +238,7 @@ def initialize_container context "when getting the info fails" do it "ignores the failure" do - @container.should_receive(:do_info).and_raise( + allow(@container).to receive(:do_info).and_raise( Warden::WardenError.new("failure")) expect do @@ -254,19 +254,19 @@ def initialize_container end it "should not call #do_stop" do - @container.should_not_receive(:do_stop) + expect(@container).to_not receive(:do_stop) @container.dispatch(Warden::Protocol::DestroyRequest.new) end end context "when not yet stopped" do it "should call #do_stop" do - @container.should_receive(:do_stop) + allow(@container).to receive(:do_stop) @container.dispatch(Warden::Protocol::DestroyRequest.new) end it "should not care if #do_stop succeeds" do - @container.should_receive(:do_stop).and_raise(Warden::WardenError.new("failure")) + allow(@container).to receive(:do_stop).and_raise(Warden::WardenError.new("failure")) expect do @container.dispatch(Warden::Protocol::DestroyRequest.new) @@ -276,7 +276,7 @@ def initialize_container context "when do_destroy fails" do before do - @container.should_receive(:do_destroy).and_raise(Warden::WardenError.new("failure")) + allow(@container).to receive(:do_destroy).and_raise(Warden::WardenError.new("failure")) end it "should not be destroyed" do @@ -296,7 +296,7 @@ def initialize_container end it "should not delete the snapshot" do - @container.should_receive(:delete_snapshot).once + allow(@container).to receive(:delete_snapshot).once expect do @container.dispatch(Warden::Protocol::DestroyRequest.new) @@ -328,7 +328,7 @@ def initialize_container end it "should setup grace timer" do - container.should_receive(:setup_grace_timer) + allow(container).to receive(:setup_grace_timer) connection.emit(:close) end end @@ -336,12 +336,12 @@ def initialize_container context "grace timer" do context "when unspecified" do it "should fire after server-wide grace time" do - Warden::Server.should_receive(:container_grace_time).and_return(0.02) + allow(Warden::Server).to receive(:container_grace_time).and_return(0.02) @container = initialize_container em do - @container.should_receive(:fire_grace_timer) + allow(@container).to receive(:fire_grace_timer) @container.setup_grace_timer ::EM.add_timer(0.03) { done } @@ -355,7 +355,7 @@ def initialize_container @container.grace_time = nil em do - @container.should_not_receive(:fire_grace_timer) + expect(@container).to_not receive(:fire_grace_timer) @container.setup_grace_timer ::EM.add_timer(0.03) { done } @@ -376,7 +376,7 @@ def initialize_container it "should not fire" do em do - @container.should_not_receive(:fire_grace_timer) + expect(@container).to_not receive(:fire_grace_timer) @container.setup_grace_timer ::EM.add_timer(0.01) { @container.cancel_grace_timer } @@ -388,7 +388,7 @@ def initialize_container context "when the last connection closed" do it "should fire after grace time" do em do - @container.should_receive(:fire_grace_timer) + allow(@container).to receive(:fire_grace_timer) @container.setup_grace_timer ::EM.add_timer(0.03) { done } @@ -397,7 +397,7 @@ def initialize_container it "should not fire when timer is cancelled" do em do - @container.should_not_receive(:fire_grace_timer) + expect(@container).to_not receive(:fire_grace_timer) @container.setup_grace_timer ::EM.add_timer(0.01) { @container.cancel_grace_timer } @@ -408,7 +408,7 @@ def initialize_container context "when fired" do it "should destroy container" do em do - @container.should_receive(:dispatch). + allow(@container).to receive(:dispatch). with(Warden::Protocol::DestroyRequest.new) @container.setup_grace_timer @@ -418,7 +418,7 @@ def initialize_container it "should ignore any WardenError raised by destroy" do em do - @container.should_receive(:dispatch). + allow(@container).to receive(:dispatch). with(Warden::Protocol::DestroyRequest.new). and_raise(Warden::WardenError.new("failure")) @container.setup_grace_timer @@ -599,7 +599,7 @@ def initialize_container describe "spawn" do before(:each) do @job = double("job", :job_id => 1) - @container.stub(:create_job).and_return(@job) + allow(@container).to receive(:create_job).and_return(@job) end include_examples "succeeds when active", Proc.new { @@ -610,7 +610,7 @@ def initialize_container describe "run" do let(:job) { double("job", :job_id => 1, :err => nil, :yield => [0, "", ""], :cleanup => nil) } before(:each) do - container.stub(:create_job).and_return(job) + allow(container).to receive(:create_job).and_return(job) end include_examples "succeeds when active", Proc.new { @@ -619,12 +619,12 @@ def initialize_container context "when job yielded with error" do before do - job.stub(:err) { WardenError.new("failed to do the job") } + allow(job).to receive(:err) { WardenError.new("failed to do the job") } it "saves the error message in response events" do container.dispatch(Warden::Protocol::CreateRequest.new) response = container.dispatch(Warden::Protocol::RunRequest.new) - response.info.events.should include("failed to do the job") + expect(response.info.events).to include("failed to do the job") end end end @@ -632,7 +632,7 @@ def initialize_container describe "net_in" do before(:each) do - @container.stub(:do_net_in) + allow(@container).to receive(:do_net_in) end include_examples "succeeds when active", Proc.new { @@ -642,7 +642,7 @@ def initialize_container describe "net_out" do before(:each) do - @container.stub(:do_net_out) + allow(@container).to receive(:do_net_out) end include_examples "succeeds when active", Proc.new { @@ -652,7 +652,7 @@ def initialize_container describe "copy_in" do before(:each) do - @container.stub(:do_copy_in) + allow(@container).to receive(:do_copy_in) end include_examples "succeeds when active", Proc.new { @@ -662,7 +662,7 @@ def initialize_container describe "copy_out" do before(:each) do - @container.stub(:do_copy_out) + allow(@container).to receive(:do_copy_out) end include_examples "succeeds when active or stopped", Proc.new { @@ -672,7 +672,7 @@ def initialize_container describe "limit_memory" do before(:each) do - @container.stub(:do_limit_memory) + allow(@container).to receive(:do_limit_memory) end include_examples "succeeds when active or stopped", Proc.new { @@ -682,7 +682,7 @@ def initialize_container describe "limit_disk" do before(:each) do - @container.stub(:do_limit_disk) + allow(@container).to receive(:do_limit_disk) end include_examples "succeeds when active or stopped", Proc.new { @@ -692,7 +692,7 @@ def initialize_container describe "limit_bandwidth" do before(:each) do - @container.stub(:do_limit_bandwidth) + allow(@container).to receive(:do_limit_bandwidth) end include_examples "succeeds when active or stopped", Proc.new { @@ -702,7 +702,7 @@ def initialize_container describe "limit_cpu" do before(:each) do - @container.stub(:do_limit_cpu) + allow(@container).to receive(:do_limit_cpu) end include_examples "succeeds when active or stopped", Proc.new { diff --git a/warden/spec/container/features/quota_spec.rb b/warden/spec/container/features/quota_spec.rb index 1a8211bc..7cc5466d 100644 --- a/warden/spec/container/features/quota_spec.rb +++ b/warden/spec/container/features/quota_spec.rb @@ -14,10 +14,10 @@ end before do - instance.class.stub(:container_depot_mount_point_path).and_return("/") - instance.class.stub(:container_depot_block_size).and_return(4096) + allow(instance.class).to receive(:container_depot_mount_point_path).and_return("/") + allow(instance.class).to receive(:container_depot_block_size).and_return(4096) - instance.stub(:uid).and_return(1001) + allow(instance).to receive(:uid).and_return(1001) @current_limits = {} @default_limits = { @@ -27,7 +27,7 @@ :inode_hard => 0, } - instance.class.stub(:repquota) do |uid| + allow(instance.class).to receive(:repquota) do |uid| { uid => { :quota => { @@ -44,7 +44,7 @@ } end - instance.stub(:setquota) do |_, limits| + allow(instance).to receive(:setquota) do |_, limits| @current_limits = limits end end @@ -55,14 +55,14 @@ describe "setting 'block_soft'" do before do - instance.class.stub(:disk_quota_enabled).and_return(true) + allow(instance.class).to receive(:disk_quota_enabled).and_return(true) end after do instance.do_limit_disk(request, response) - response.byte_soft.should == 4096 - response.block_soft.should == 1 + expect(response.byte_soft).to eq 4096 + expect(response.block_soft).to eq 1 end %W(byte_soft).each do |byte_property| @@ -91,19 +91,19 @@ describe "setting 'block_hard'" do before do - instance.class.stub(:disk_quota_enabled).and_return(true) + allow(instance.class).to receive(:disk_quota_enabled).and_return(true) end after do instance.do_limit_disk(request, response) - response.byte_limit.should == 4096 - response.byte.should == 4096 - response.byte_hard.should == 4096 + expect(response.byte_limit).to eq 4096 + expect(response.byte).to eq 4096 + expect(response.byte_hard).to eq 4096 - response.block_limit.should == 1 - response.block.should == 1 - response.block_hard.should == 1 + expect(response.block_limit).to eq 1 + expect(response.block).to eq 1 + expect(response.block_hard).to eq 1 end %W(byte_limit byte byte_hard).each do |byte_property| @@ -132,13 +132,13 @@ describe "setting 'inode_soft'" do before do - instance.class.stub(:disk_quota_enabled).and_return(true) + allow(instance.class).to receive(:disk_quota_enabled).and_return(true) end after do instance.do_limit_disk(request, response) - response.inode_soft.should == 1024 + expect(response.inode_soft).to eq 1024 end %W(inode_soft).each do |inode_property| @@ -154,15 +154,15 @@ describe "setting 'inode_hard'" do before do - instance.class.stub(:disk_quota_enabled).and_return(true) + allow(instance.class).to receive(:disk_quota_enabled).and_return(true) end after do instance.do_limit_disk(request, response) - response.inode_limit.should == 1024 - response.inode.should == 1024 - response.inode_hard.should == 1024 + expect(response.inode_limit).to eq 1024 + expect(response.inode).to eq 1024 + expect(response.inode_hard).to eq 1024 end %W(inode_limit inode inode_hard).each do |inode_property| @@ -178,7 +178,7 @@ describe "disabling disk quota" do before do - instance.class.stub(:disk_quota_enabled).and_return(false) + allow(instance.class).to receive(:disk_quota_enabled).and_return(false) end after do @@ -188,9 +188,9 @@ block_property = byte_property.gsub("byte", "block") inode_property = byte_property.gsub("byte", "inode") - response.method(byte_property ).call.should be_nil - response.method(block_property).call.should be_nil - response.method(inode_property).call.should be_nil + expect(response.method(byte_property ).call).to be_nil + expect(response.method(block_property).call).to be_nil + expect(response.method(inode_property).call).to be_nil end end diff --git a/warden/spec/container/insecure_spec.rb b/warden/spec/container/insecure_spec.rb index e741d96a..adbd4106 100644 --- a/warden/spec/container/insecure_spec.rb +++ b/warden/spec/container/insecure_spec.rb @@ -109,7 +109,7 @@ def client def net_in(options = {}) response = client.net_in(options.merge(:handle => handle)) - response.should be_ok + expect(response).to be_ok response end @@ -128,7 +128,7 @@ def check_mapping(response) external_ip = `ip route get 1.1.1.1`.split(/\n/).first.split(/\s+/).last # Pipe echo to give nc a stdin (it quits immediately after connecting if it doesn't have a stdin) - `echo | nc #{external_ip} #{response.host_port}`.chomp.should == "ok" + expect(`echo | nc #{external_ip} #{response.host_port}`.chomp).to eq "ok" # Clean up client.link(:handle => handle, :job_id => job_id) @@ -141,7 +141,7 @@ def check_mapping(response) it "should ignore the port on the container side if specified" do response = net_in(:container_port => 1234) - response.container_port.should_not == 1234 + expect(response.container_port).to_not eq 1234 check_mapping(response) end end diff --git a/warden/spec/container/linux_nested_spec.rb b/warden/spec/container/linux_nested_spec.rb index d014dfe5..884893dd 100644 --- a/warden/spec/container/linux_nested_spec.rb +++ b/warden/spec/container/linux_nested_spec.rb @@ -77,7 +77,7 @@ def execute(command) `#{command}`.tap do - $?.should be_success + expect($?).to be_success end end @@ -168,13 +168,13 @@ def run_as_root(script, background = false) puts "---------------------------- exit status: #{exit_status}" if debug? - exit_status.should == 0 + expect(exit_status).to eq 0 end end def create response = client.call(@create_request) - response.should be_ok + expect(response).to be_ok @handle = response.handle end @@ -217,7 +217,7 @@ def create destroy = Warden::Protocol::DestroyRequest.new destroy.handle = @handle - client.call(destroy).should be_ok + expect(client.call(destroy)).to be_ok end end diff --git a/warden/spec/container/linux_spec.rb b/warden/spec/container/linux_spec.rb index da696716..35353e7d 100644 --- a/warden/spec/container/linux_spec.rb +++ b/warden/spec/container/linux_spec.rb @@ -14,10 +14,10 @@ describe "linux", :platform => "linux", :needs_root => true do include Helpers::Drain - let(:work_path) { File.join(Dir.tmpdir, "warden", "spec") } + attr_reader :container_rootfs_path, :work_path + let(:unix_domain_path) { File.join(work_path, "warden.sock") } let(:container_klass) { "Warden::Container::Linux" } - let(:container_rootfs_path) { File.join(work_path, "..", "rootfs") } let(:container_depot_path) { File.join(work_path, "containers") } let(:container_depot_file) { container_depot_path + ".img" } let(:have_uid_support) { true } @@ -31,6 +31,11 @@ let(:syslog_socket) { nil } let(:lang) { ENV['LANG'] } + before(:all) do + @work_path = File.join(Dir.tmpdir, "warden", "spec") + @container_rootfs_path = File.join(work_path, "..", "rootfs") + end + before do FileUtils.mkdir_p(work_path) @@ -71,7 +76,7 @@ def execute(command) `#{command}`.tap do - $?.should be_success + expect($?).to be_success end end @@ -189,9 +194,9 @@ def reset_client it "should honor the host's LANG" do response = client.run(:handle => handle, :script => "locale | grep LANG=") - response.exit_status.should == 0 - response.stdout.strip.should == "LANG=#{lang}" - response.stderr.should == "" + expect(response.exit_status).to eq 0 + expect(response.stdout.strip).to eq "LANG=#{lang}" + expect(response.stderr).to eq "" end context "when LANG is not set" do @@ -199,9 +204,9 @@ def reset_client it "defaults to en_US.UTF-8" do response = client.run(:handle => handle, :script => "locale | grep LANG=") - response.exit_status.should == 0 - response.stdout.strip.should == 'LANG=en_US.UTF-8' - response.stderr.should == "" + expect(response.exit_status).to eq 0 + expect(response.stdout.strip).to eq 'LANG=en_US.UTF-8' + expect(response.stderr).to eq "" end end end @@ -211,13 +216,13 @@ def reset_client def limit_memory(options = {}) response = client.limit_memory(options.merge(:handle => handle)) - response.should be_ok + expect(response).to be_ok response end def run(script) response = client.run(:handle => handle, :script => script) - response.should be_ok + expect(response).to be_ok response end @@ -235,7 +240,7 @@ def trigger_oom it "should default to a large number" do response = limit_memory - response.limit_in_bytes.should == 9223372036854771712 + expect(response.limit_in_bytes).to eq 9223372036854771712 end describe "setting limits" do @@ -247,29 +252,29 @@ def integer_from_memory_cgroup(file) before do response = limit_memory(:limit_in_bytes => hundred_mb) - response.limit_in_bytes.should == hundred_mb + expect(response.limit_in_bytes).to eq hundred_mb end it "sets `memory.limit_in_bytes`" do - integer_from_memory_cgroup("memory.limit_in_bytes").should == hundred_mb + expect(integer_from_memory_cgroup("memory.limit_in_bytes")).to eq hundred_mb end it "sets `memory.memsw.limit_in_bytes`" do - integer_from_memory_cgroup("memory.memsw.limit_in_bytes").should == hundred_mb + expect(integer_from_memory_cgroup("memory.memsw.limit_in_bytes")).to eq hundred_mb end describe "increasing limits" do before do response = limit_memory(:limit_in_bytes => 2 * hundred_mb) - response.limit_in_bytes.should == 2 * hundred_mb + expect(response.limit_in_bytes).to eq 2 * hundred_mb end it "sets `memory.limit_in_bytes`" do - integer_from_memory_cgroup("memory.limit_in_bytes").should == 2 * hundred_mb + expect(integer_from_memory_cgroup("memory.limit_in_bytes")).to eq 2 * hundred_mb end it "sets `memory.memsw.limit_in_bytes`" do - integer_from_memory_cgroup("memory.memsw.limit_in_bytes").should == 2 * hundred_mb + expect(integer_from_memory_cgroup("memory.memsw.limit_in_bytes")).to eq 2 * hundred_mb end end end @@ -279,8 +284,8 @@ def self.it_should_stop_container_when_an_oom_event_occurs trigger_oom response = client.info(:handle => handle) - response.state.should == "stopped" - response.events.should include("out of memory") + expect(response.state).to eq "stopped" + expect(response.events).to include("out of memory") end end @@ -322,7 +327,7 @@ def limit_disk(options = {}) end response = client.limit_disk(options) - response.should be_ok + expect(response).to be_ok response end @@ -331,7 +336,7 @@ def run(script, container_handle = "") container_handle = handle end response = client.run(:handle => container_handle, :script => script) - response.should be_ok + expect(response).to be_ok response end @@ -366,28 +371,22 @@ def perform_rsync(src_path, dst_path, exclude_pattern = '') FileUtils.rm_rf(vcap_rootfs_path) end + vcap_id = `grep vcap: #{container_rootfs_path}/etc/passwd | cut -d ':' -f 3`.strip + perform_rsync(container_rootfs_path, vcap_rootfs_path, "mnt/dev/*") FileUtils.mkdir_p(vcap_home_directory) FileUtils.touch(vcap_home_file) FileUtils.touch(vcap_tmp_file) - FileUtils.chown(10000, 10000, vcap_home_directory) - FileUtils.chown(10000, 10000, vcap_home_file) - FileUtils.chown(10000, 10000, vcap_tmp_file) - - open("#{vcap_rootfs_path}/etc/passwd", 'a') do |passwd_file| - passwd_file.puts 'vcap:x:10000:10000:vcap:/home/vcap:/bin/bash' - end - - open("#{vcap_rootfs_path}/etc/group", 'a') do |group_file| - group_file.puts 'vcap:x:10000:' - end + FileUtils.chown(vcap_id, vcap_id, vcap_home_directory) + FileUtils.chown(vcap_id, vcap_id, vcap_home_file) + FileUtils.chown(vcap_id, vcap_id, vcap_tmp_file) create_request = Warden::Protocol::CreateRequest.new create_request.rootfs = vcap_rootfs_path expect { @vcap_handle = client.call(create_request).handle - }.to_not raise_error Warden::Client::ServerError + }.to_not raise_error end it 'should apply different disk quota on every container' do @@ -395,48 +394,48 @@ def perform_rsync(src_path, dst_path, exclude_pattern = '') vcap_limit_response = limit_disk(:handle => vcap_handle, :byte_limit => 4 * 1024 * 1024) limit_response = limit_disk() - limit_response.byte_limit.should == 4 * 1024 * 1024 + expect(limit_response.byte_limit).to eq 4 * 1024 * 1024 vcap_limit_response = limit_disk(:handle => vcap_handle) - vcap_limit_response.byte_limit.should == 4 * 1024 * 1024 + expect(vcap_limit_response.byte_limit).to eq 4 * 1024 * 1024 response = run("dd if=/dev/zero of=/tmp/test bs=1M count=3") - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 response = run("dd if=/dev/zero of=/tmp/test bs=1M count=3", vcap_handle) - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 end it "should still own vcap's files" do response = run("stat -c %u /home/vcap/a_file.txt", vcap_handle) - response.exit_status.should == 0 - response.stdout.strip!.should == "10001" + expect(response.exit_status).to eq 0 + expect(response.stdout.strip!).to eq "10001" response = run("stat -c %g /home/vcap/a_file.txt", vcap_handle) - response.exit_status.should == 0 - response.stdout.strip!.should == "10001" + expect(response.exit_status).to eq 0 + expect(response.stdout.strip!).to eq "10001" response = run("stat -c %u /tmp/a_file.txt", vcap_handle) - response.exit_status.should == 0 - response.stdout.strip!.should == "10001" + expect(response.exit_status).to eq 0 + expect(response.stdout.strip!).to eq "10001" response = run("stat -c %g /tmp/a_file.txt", vcap_handle) - response.exit_status.should == 0 - response.stdout.strip!.should == "10001" + expect(response.exit_status).to eq 0 + expect(response.stdout.strip!).to eq "10001" response = run("cat /etc/passwd | grep vcap: | cut -d ':' -f 3", vcap_handle) - response.exit_status.should == 0 - response.stdout.strip.should == "10001" + expect(response.exit_status).to eq 0 + expect(response.stdout.strip).to eq "10001" response = run("cat /etc/group | grep vcap: | cut -d ':' -f 3", vcap_handle) - response.exit_status.should == 0 - response.stdout.strip.should == "10001" + expect(response.exit_status).to eq 0 + expect(response.stdout.strip).to eq "10001" end end it "should allow the disk quota to be changed" do response = limit_disk(:block_limit => 12345) - response.block_limit.should == 12345 + expect(response.block_limit).to eq 12345 end it "should set the block quota to 0 on creation" do @@ -445,7 +444,7 @@ def perform_rsync(src_path, dst_path, exclude_pattern = '') # and destroy containers until we have exhausted the UID pool and # re-use an UID for the first time. The test is kept as a reminder. response = limit_disk() - response.block_limit.should == 0 + expect(response.block_limit).to eq 0 end context "with a 2M disk limit" do @@ -455,13 +454,13 @@ def perform_rsync(src_path, dst_path, exclude_pattern = '') it "should succeed to write a 1M file" do response = run("dd if=/dev/zero of=/tmp/test bs=1M count=1") - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 end it "should fail to write a 4M file" do response = run("dd if=/dev/zero of=/tmp/test bs=1M count=4") - response.exit_status.should == 1 - response.stderr.should =~ /quota exceeded/i + expect(response.exit_status).to eq 1 + expect(response.stderr).to match /quota exceeded/i end end end @@ -477,7 +476,7 @@ def perform_rsync(src_path, dst_path, exclude_pattern = '') def run response = client.run(options) - response.should be_ok + expect(response).to be_ok response end @@ -488,7 +487,7 @@ def run it "should save event" do response = run - response.info.events.should include("command exceeded maximum output") + expect(response.info.events).to include("command exceeded maximum output") end context "when output is discarded" do @@ -496,7 +495,7 @@ def run it "does not save an event as the job is not killed" do response = run - response.info.events.should be_nil + expect(response.info.events).to be_nil end end end @@ -507,7 +506,7 @@ def run def limit_bandwidth(options = {}) response = client.limit_bandwidth(options.merge(:handle => handle)) - response.should be_ok + expect(response).to be_ok response end @@ -519,10 +518,10 @@ def limit_bandwidth(options = {}) response = limit_bandwidth(:rate => 100 * 1000, :burst => 1000) ret = client.info(:handle => handle) [ret.bandwidth_stat.in_rate, ret.bandwidth_stat.out_rate].each do |v| - v.should == 100 * 1000 + expect(v).to eq 100 * 1000 end [ret.bandwidth_stat.in_burst, ret.bandwidth_stat.out_burst].each do |v| - v.should == 1000 + expect(v).to eq 1000 end end @@ -530,10 +529,10 @@ def limit_bandwidth(options = {}) response = limit_bandwidth(:rate => 200 * 1000, :burst => 2000) ret = client.info(:handle => handle) [ret.bandwidth_stat.in_rate, ret.bandwidth_stat.out_rate].each do |v| - v.should == 200 * 1000 + expect(v).to eq 200 * 1000 end [ret.bandwidth_stat.in_burst, ret.bandwidth_stat.out_burst].each do |v| - v.should == 2000 + expect(v).to eq 2000 end end end @@ -547,7 +546,7 @@ def integer_from_cgroup_cpu_shares def limit_cpu(options = {}) response = client.limit_cpu(options.merge(:handle => handle)) - response.should be_ok + expect(response).to be_ok response end @@ -591,13 +590,13 @@ def limit_cpu(options = {}) describe "net_out" do def net_out(options = {}) response = client.net_out(options) - response.should be_ok + expect(response).to be_ok response end def run(handle, script) response = client.run(:handle => handle, :script => script) - response.should be_ok + expect(response).to be_ok response end @@ -678,7 +677,7 @@ def host_first_ipv4 end it "rejects outbound tcp traffic" do - client.net_out(:handle => handle, :port => 53, :protocol => Warden::Protocol::NetOutRequest::Protocol::UDP).should be_ok + expect(client.net_out(:handle => handle, :port => 53, :protocol => Warden::Protocol::NetOutRequest::Protocol::UDP)).to be_ok client_script = "curl -s --connect-timeout 15 http://www.example.com/ -o /dev/null" response = run(handle, client_script) @@ -686,7 +685,7 @@ def host_first_ipv4 end it "rejects outbound icmp traffic" do - client.net_out(:handle => handle, :port => 53, :protocol => Warden::Protocol::NetOutRequest::Protocol::UDP).should be_ok + expect(client.net_out(:handle => handle, :port => 53, :protocol => Warden::Protocol::NetOutRequest::Protocol::UDP)).to be_ok client_script = "ping -w2 -c1 www.example.com" response = run(handle, client_script) @@ -791,7 +790,7 @@ def verify_icmp_connectivity_to_host(handle) it "reaches every container from the host" do @containers.each do |e| `ping -q -w2 -c1 #{e[:ip]}` - $?.should == 0 + expect($?).to eq 0 end end @@ -803,15 +802,15 @@ def verify_icmp_connectivity_to_host(handle) end it "allows traffic to networks configured in allowed networks" do - reachable?(@containers[0][:handle], host_gw_ip).should be_true - reachable?(@containers[1][:handle], host_gw_ip).should be_true - reachable?(@containers[2][:handle], host_gw_ip).should be_true + expect(reachable?(@containers[0][:handle], host_gw_ip)).to be true + expect(reachable?(@containers[1][:handle], host_gw_ip)).to be true + expect(reachable?(@containers[2][:handle], host_gw_ip)).to be true end it "disallows traffic to networks that are not configured in allowed networks" do - reachable?(@containers[0][:handle], "8.8.8.8").should be_false - reachable?(@containers[1][:handle], "8.8.8.8").should be_false - reachable?(@containers[2][:handle], "8.8.8.8").should be_false + expect(reachable?(@containers[0][:handle], "8.8.8.8")).to be false + expect(reachable?(@containers[1][:handle], "8.8.8.8")).to be false + expect(reachable?(@containers[2][:handle], "8.8.8.8")).to be false end end @@ -984,15 +983,15 @@ def verify_icmp_connectivity_to_host(handle) end it "should not raise error when network field is present" do - net_out(:handle => handle, :network => "4.2.2.2").should be_ok + expect(net_out(:handle => handle, :network => "4.2.2.2")).to be_ok end it "should not raise error when port field is present" do - net_out(:handle => handle, :port => 1234).should be_ok + expect(net_out(:handle => handle, :port => 1234)).to be_ok end it "should not raise error when both network and port fields are present" do - net_out(:handle => handle, :network => "4.2.2.2", :port => 1234).should be_ok + expect(net_out(:handle => handle, :network => "4.2.2.2", :port => 1234)).to be_ok end it "should raise an error when the port range specifies min > max" do @@ -1014,7 +1013,7 @@ def verify_icmp_connectivity_to_host(handle) def net_in(options = {}) response = client.net_in(options.merge(:handle => handle)) - response.should be_ok + expect(response).to be_ok response end @@ -1065,27 +1064,27 @@ def check_mapping(response) it "should allow the port on the container side to be specified" do response = net_in(:container_port => 8080) - response.container_port.should == 8080 + expect(response.container_port).to eq 8080 check_mapping(response) end it "should allow the port on the host side to be specified" do response = net_in(:host_port => 8080) - response.host_port.should == 8080 - response.container_port.should == 8080 + expect(response.host_port).to eq 8080 + expect(response.container_port).to eq 8080 check_mapping(response) end it "should allow the port on both of the container and host sides to be specified" do response = net_in(:host_port => 8080, :container_port => 8081) - response.host_port.should == 8080 - response.container_port.should == 8081 + expect(response.host_port).to eq 8080 + expect(response.container_port).to eq 8081 check_mapping(response) end it "should not redirect requests to other servers' container_port" do - client.net_out(:handle => handle, :port => 80).should be_ok - client.net_out(:handle => handle, :port => 53, :protocol => Warden::Protocol::NetOutRequest::Protocol::UDP).should be_ok + expect(client.net_out(:handle => handle, :port => 80)).to be_ok + expect(client.net_out(:handle => handle, :port => 53, :protocol => Warden::Protocol::NetOutRequest::Protocol::UDP)).to be_ok net_in(:host_port => 80, :container_port => 8080) script = "curl -s -w '%{http_code}' http://www.example.com/ -o /dev/null" @@ -1105,37 +1104,37 @@ def check_mapping(response) it "should include memory stat" do response = client.info(:handle => handle) - response.memory_stat.rss.should > 0 + expect(response.memory_stat.rss).to be > 0 end it "should include cpu stat" do response = client.info(:handle => handle) - response.cpu_stat.usage.should > 0 - response.cpu_stat.user.should >= 0 - response.cpu_stat.system.should >= 0 + expect(response.cpu_stat.usage).to be > 0 + expect(response.cpu_stat.user).to be >= 0 + expect(response.cpu_stat.system).to be >= 0 end it "should include disk stat" do response = client.info(:handle => handle) - response.disk_stat.inodes_used.should > 0 + expect(response.disk_stat.inodes_used).to be > 0 bytes_used = response.disk_stat.bytes_used - bytes_used.should > 0 + expect(bytes_used).to be > 0 response = client.run(:handle => handle, :script => "dd if=/dev/urandom of=/tmp/foo bs=1MB count=1") - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 response = client.info(:handle => handle) - response.disk_stat.bytes_used.should be_within(32000).of(bytes_used + 1_000_000) + expect(response.disk_stat.bytes_used).to be_within(32000).of(bytes_used + 1_000_000) end it "should include bandwidth stat" do response = client.info(:handle => handle) [response.bandwidth_stat.in_rate, response.bandwidth_stat.out_rate].each do |x| - x.should >= 0 + expect(x).to be >= 0 end [response.bandwidth_stat.in_burst, response.bandwidth_stat.out_burst].each do |x| - x.should >= 0 + expect(x).to be >= 0 end end @@ -1151,7 +1150,7 @@ def check_mapping(response) sleep 0.1 response = client.info(:handle => handle) - response.job_ids.should == [job_id_1] + expect(response.job_ids).to eq [job_id_1] end end @@ -1165,13 +1164,13 @@ def check_mapping(response) def run(script) response = client.run(:handle => handle, :script => script) - response.should be_ok + expect(response).to be_ok response end def create response = client.call(@create_request) - response.should be_ok + expect(response).to be_ok @handle = response.handle end @@ -1191,7 +1190,7 @@ def create after do # Mounts should not appear in /etc/mtab - File.read("/etc/mtab").should_not match(Regexp.escape(@bind_mount.src_path)) + expect(File.read("/etc/mtab")).to_not match(Regexp.escape(@bind_mount.src_path)) end after :each do @@ -1204,14 +1203,14 @@ def create # Make sure we CAN READ a file that already exists response = run "cat #{@bind_mount.dst_path}/#{test_basename}" - response.exit_status.should == 0 - response.stdout.should == test_contents + expect(response.exit_status).to eq 0 + expect(response.stdout).to eq test_contents # Make sure we CAN'T WRITE a file response = run "touch #{@bind_mount.dst_path}/test" - response.exit_status.should == 1 - response.stdout.should be_empty - response.stderr.should match(/read-only file system/i) + expect(response.exit_status).to eq 1 + expect(response.stdout).to be_empty + expect(response.stderr).to match(/read-only file system/i) end it "should support bind mounting in RW mode" do @@ -1220,14 +1219,14 @@ def create # Make sure we CAN READ a file that already exists response = run "cat #{@bind_mount.dst_path}/#{test_basename}" - response.exit_status.should == 0 - response.stdout.should == test_contents + expect(response.exit_status).to eq 0 + expect(response.stdout).to eq test_contents # Make sure we CAN WRITE a file response = run "touch #{@bind_mount.dst_path}/test" - response.exit_status.should == 0 - response.stdout.should be_empty - response.stderr.should be_empty + expect(response.exit_status).to eq 0 + expect(response.stdout).to be_empty + expect(response.stderr).to be_empty end it "should return an error when a bind mount does not exist" do @@ -1248,34 +1247,34 @@ def create before do response = client.create - response.should be_ok + expect(response).to be_ok @handle = response.handle end def run(script) response = client.run(:handle => handle, :script => script) - response.should be_ok + expect(response).to be_ok response end it "is a directory" do response = run("[ -d /dev/shm ]") - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 end it "is mounted as a tmpfs device" do response = run("grep /dev/shm /proc/mounts") - response.exit_status.should == 0 - response.stdout.should match(/tmpfs/) + expect(response.exit_status).to eq 0 + expect(response.stdout).to match(/tmpfs/) end it "can be written to by unprivileged users" do response = run("id -u > /dev/shm/id.txt") - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 response = run("cat /dev/shm/id.txt") - response.stdout.strip.should_not eq('0') + expect(response.stdout.strip).to_not eq('0') end context "when there is a memory limit" do @@ -1284,17 +1283,17 @@ def run(script) before do response = client.limit_memory(:handle => handle, :limit_in_bytes => memory_limit) - response.limit_in_bytes.should == memory_limit + expect(response.limit_in_bytes).to eq memory_limit end it "can write less than the memory limit" do run("dd of=/dev/shm/out.bin if=/dev/urandom bs=#{megabyte} count=30") response = client.info(:handle => handle) - response.state.should == "active" + expect(response.state).to eq "active" response = run("du -m /dev/shm/out.bin | cut -f1") - response.stdout.strip.to_i.should be(30) + expect(response.stdout.strip.to_i).to be(30) end it "terminates when writing more data than the memory limit" do @@ -1302,8 +1301,8 @@ def run(script) sleep 0.20 # wait a bit for the warden to be notified of the oom response = client.info(:handle => handle) - response.state.should == "stopped" - response.events.should include("out of memory") + expect(response.state).to eq "stopped" + expect(response.events).to include("out of memory") end end end @@ -1311,7 +1310,7 @@ def run(script) describe "network devices" do let(:handle) do response = client.create - response.should be_ok + expect(response).to be_ok response.handle end @@ -1319,38 +1318,38 @@ def run(script) it "activates a host side network adapter" do script = "/sbin/ifconfig w-#{handle}-0 | grep -Eo 'RUNNING'" response = execute(script) - response.should eq("RUNNING\n") + expect(response).to eq("RUNNING\n") end it "activates a container side network adapter" do script = "/sbin/ifconfig w-#{handle}-1 | grep -Eo 'RUNNING'" response = client.run(:handle => handle, :script => script) - response.exit_status.should == 0 - response.stdout.should eq("RUNNING\n") + expect(response.exit_status).to eq 0 + expect(response.stdout).to eq("RUNNING\n") end it "activates a host side ifb network adapter" do script = "/sbin/ifconfig w-#{handle}-2 | grep -Eo 'RUNNING'" response = execute(script) - response.should eq("RUNNING\n") + expect(response).to eq("RUNNING\n") end context "when the container is destroyed" do before do response = client.destroy(:handle => handle) - response.should be_ok + expect(response).to be_ok end it "destroys the host side network adapter" do script = "/sbin/ifconfig -a" response = execute(script) - response.should_not include("w-#{handle}-0") + expect(response).to_not include("w-#{handle}-0") end it "destroys the host side ifb network adapter" do script = "/sbin/ifconfig -a" response = execute(script) - response.should_not include("w-#{handle}-2") + expect(response).to_not include("w-#{handle}-2") end end end @@ -1361,7 +1360,7 @@ def run(script) create_request.network = @start_address response = client.call(create_request) - response.should be_ok + expect(response).to be_ok info_request = Warden::Protocol::InfoRequest.new info_request.handle = response.handle @@ -1369,7 +1368,7 @@ def run(script) response = client.call(info_request) network = Warden::Network::Address.new(response.container_ip).network(netmask) - network.to_human.should == @start_address + expect(network.to_human).to eq @start_address end it "should raise error to use network not in the pool" do @@ -1390,11 +1389,11 @@ def run(script) create_request.network = @start_address response = client.call(create_request) - response.should be_ok + expect(response).to be_ok script = "/sbin/ifconfig w-#{response.handle}-1 | grep -Eo 'MTU:[0-9]+'" mtu_response = client.run(:handle => response.handle, :script => script) - mtu_response.stdout.should == "MTU:1454\n" + expect(mtu_response.stdout).to eq "MTU:1454\n" end it "should set host side MTU" do @@ -1402,11 +1401,11 @@ def run(script) create_request.network = @start_address response = client.call(create_request) - response.should be_ok + expect(response).to be_ok script = "/sbin/ifconfig w-#{response.handle}-0 | grep -Eo 'MTU:[0-9]+'" mtu_response = execute("#{script}") - mtu_response.should == "MTU:1454\n" + expect(mtu_response).to eq "MTU:1454\n" end it "should set the host ifb adapter MTU" do @@ -1414,11 +1413,11 @@ def run(script) create_request.network = @start_address response = client.call(create_request) - response.should be_ok + expect(response).to be_ok script = "/sbin/ifconfig w-#{response.handle}-2 | grep -Eo 'MTU:[0-9]+'" mtu_response = execute("#{script}") - mtu_response.should == "MTU:1454\n" + expect(mtu_response).to eq "MTU:1454\n" end end @@ -1437,7 +1436,7 @@ def run(script) create_request.rootfs = another_rootfs_path response = client.call(create_request) - response.should be_ok + expect(response).to be_ok end it "should raise error on bad rootfs path" do @@ -1459,9 +1458,9 @@ def run(script) it "should run commands as root if the privileged option is set" do response = client.run(:handle => handle, :script => "id -u", :privileged => true) - response.exit_status.should == 0 - response.stdout.should == "0\n" - response.stderr.should == "" + expect(response.exit_status).to eq 0 + expect(response.stdout).to eq "0\n" + expect(response.stderr).to eq "" end end @@ -1475,9 +1474,9 @@ def run(script) it "should be configurable" do rlimits = Warden::Protocol::ResourceLimits.new(:nofile => 1234) response = client.run(:handle => handle, :script => "ulimit -n", :rlimits => rlimits) - response.exit_status.should == 0 - response.stdout.chomp.should == "1234" - response.stderr.chomp.should == "" + expect(response.exit_status).to eq 0 + expect(response.stdout.chomp).to eq "1234" + expect(response.stderr.chomp).to eq "" end end @@ -1495,23 +1494,23 @@ def run(script) reset_client containers = client.list.handles - containers.should_not include(@h1) - containers.should include(@h2) + expect(containers).to_not include(@h1) + expect(containers).to include(@h2) # Test that the path for h1 is gone h1_path = File.join(container_depot_path, @h1) - File.directory?(h1_path).should be_false + expect(File.directory?(h1_path)).to be false end it "should destroy containers without snapshot" do snapshot_path = File.join(container_depot_path, @h1, "snapshot.json") - File.exist?(snapshot_path).should be_true + expect(File.exist?(snapshot_path)).to be true File.delete(snapshot_path) end it "should destroy containers that have stopped" do wshd_pid_path = File.join(container_depot_path, @h1, "run", "wshd.pid") - File.exist?(wshd_pid_path).should be_true + expect(File.exist?(wshd_pid_path)).to be true Process.kill("KILL", File.read(wshd_pid_path).to_i) end end @@ -1535,34 +1534,34 @@ def run(script) before do response = client.create - response.should be_ok + expect(response).to be_ok @handle = response.handle end def run(script) response = client.run(:handle => handle, :script => script) - response.should be_ok + expect(response).to be_ok response end it "is a character special device" do response = run("[ -c /dev/fuse ]") - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 end it "can be used by unprivileged users" do response = run("id -u") - response.stdout.strip.should_not eq('0') + expect(response.stdout.strip).to_not eq('0') run("mkdir -p /tmp/fuse_ctl") - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 run("mount -t fusectl none /tmp/fuse_ctl") - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 run("fusermount -u /fuse_ctl") - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 end end end diff --git a/warden/spec/health_check_spec.rb b/warden/spec/health_check_spec.rb index c9d3400c..19770c9b 100644 --- a/warden/spec/health_check_spec.rb +++ b/warden/spec/health_check_spec.rb @@ -80,7 +80,7 @@ def start_warden it "should respond with HTTP 200" do uri = URI.parse("http://127.0.0.1:2345/") response = Net::HTTP.get_response(uri) - response.code.should == "200" - response.body.should be_empty + expect(response.code).to eq "200" + expect(response.body).to be_empty end end diff --git a/warden/spec/mount_point_spec.rb b/warden/spec/mount_point_spec.rb index 536a706a..5fda592c 100644 --- a/warden/spec/mount_point_spec.rb +++ b/warden/spec/mount_point_spec.rb @@ -7,13 +7,13 @@ let(:root_pathname) { double("Pathname", mountpoint?: true, to_s: "/") } before do - root_pathname.stub(realpath: root_pathname) - Pathname.stub(:new).with("/").and_return(root_pathname) + allow(root_pathname).to receive(:realpath).and_return(root_pathname) + allow(Pathname).to receive(:new).with("/").and_return(root_pathname) end context "when we ask about the root of the filesystem" do it "returns root for root" do - mount_point.for_path("/").should == "/" + expect(mount_point.for_path("/")).to eq "/" end end @@ -40,15 +40,15 @@ end before do - Pathname.stub(:new).with("/hello/world/path").and_return(path_pathname) + allow(Pathname).to receive(:new).with("/hello/world/path").and_return(path_pathname) - hello_pathname.stub(realpath: hello_pathname) - world_pathname.stub(realpath: world_pathname) - path_pathname.stub(realpath: path_pathname) + allow(hello_pathname).to receive(:realpath).and_return(hello_pathname) + allow(world_pathname).to receive(:realpath).and_return(world_pathname) + allow(path_pathname).to receive(:realpath).and_return(path_pathname) end it "returns the different mount point" do - mount_point.for_path("/hello/world/path").should == "/hello" + expect(mount_point.for_path("/hello/world/path")).to eq "/hello" end end @@ -90,15 +90,15 @@ end before do - mnt_pathname.stub(realpath: mnt_pathname) - mnt_symlink_pathname.stub(realpath: mnt_symlink_pathname) - path_pathname.stub(realpath: path_pathname) - Pathname.stub(:new).with("/hello/symlink/path").and_return(path_pathname) + allow(mnt_pathname).to receive(:realpath).and_return(mnt_pathname) + allow(mnt_symlink_pathname).to receive(:realpath).and_return(mnt_symlink_pathname) + allow(path_pathname).to receive(:realpath).and_return(path_pathname) + allow(Pathname).to receive(:new).with("/hello/symlink/path").and_return(path_pathname) end it "returns the different mount point" do - mount_point.for_path("/hello/symlink/path").should == "/mnt" + expect(mount_point.for_path("/hello/symlink/path")).to eq "/mnt" end end end -end \ No newline at end of file +end diff --git a/warden/spec/network_spec.rb b/warden/spec/network_spec.rb index 6200e4d7..9704a72c 100644 --- a/warden/spec/network_spec.rb +++ b/warden/spec/network_spec.rb @@ -10,12 +10,6 @@ def instance(*octets) end it "should raise on invalid masks" do - test = lambda { |octets| - lambda { - instance(*octets) - }.should raise_error - } - [ [255, 255, 255, 253], [255, 255, 255, 251], @@ -24,7 +18,11 @@ def instance(*octets) [255, 255, 255, 247], [255, 255, 254, 1], [255, 255, 253, 0], - ].each(&test) + ].each do |octets| + expect { + instance(*octets) + }.to raise_error + end end it "should accept valid masks" do @@ -42,15 +40,19 @@ def instance(*octets) [255, 255, 255, 240], [255, 255, 254, 0], [255, 255, 252, 0], - ].each(&test) + ].each do |octets| + expect { + instance(*octets) + }.to_not raise_error + end end it "should know its size" do - instance(255, 255, 255, 255).size.should == 1 - instance(255, 255, 255, 254).size.should == 2 - instance(255, 255, 255, 252).size.should == 4 - instance(255, 255, 254, 0).size.should == 512 - instance(255, 255, 252, 0).size.should == 1024 + expect(instance(255, 255, 255, 255).size).to eq 1 + expect(instance(255, 255, 255, 254).size).to eq 2 + expect(instance(255, 255, 255, 252).size).to eq 4 + expect(instance(255, 255, 254, 0).size).to eq 512 + expect(instance(255, 255, 252, 0).size).to eq 1024 end end @@ -58,7 +60,7 @@ def instance(*octets) it "should know its network given a mask" do mask = Warden::Network::Netmask.new(255, 255, 255, 0) address = Warden::Network::Address.new(10, 0, 128, 54) - address.network(mask).should eql Warden::Network::Address.new(10, 0, 128, 0) + expect(address.network(mask)).to eql Warden::Network::Address.new(10, 0, 128, 0) end end end diff --git a/warden/spec/pool/base_spec.rb b/warden/spec/pool/base_spec.rb index 384203c1..b4d8d14b 100644 --- a/warden/spec/pool/base_spec.rb +++ b/warden/spec/pool/base_spec.rb @@ -9,7 +9,7 @@ it "should use a block to populate" do pool = Warden::Pool::Base.new(5) { |i| i } - pool.size.should == 5 + expect(pool.size).to eq 5 end it "should take a release delay" do @@ -20,9 +20,9 @@ pool.release(entry) # It should not be possible to immediately acquire the entry again - pool.acquire.should be_nil + expect(pool.acquire).to be_nil sleep 0.02 - pool.acquire.should_not be_nil + expect(pool.acquire).to_not be_nil end end @@ -30,12 +30,12 @@ it "should return nil when empty" do pool = Warden::Pool::Base.new(0) { |i| i } - pool.acquire.should == nil + expect(pool.acquire).to eq nil end it "should return entry when not empty" do pool = Warden::Pool::Base.new(1) { |i| i } - pool.acquire.should == 0 + expect(pool.acquire).to eq 0 end end @@ -43,18 +43,18 @@ it "should return nil when empty" do pool = Warden::Pool::Base.new(0) { |i| i } - pool.fetch(0).should == nil + expect(pool.fetch(0)).to eq nil end it "should return entry when it exists" do pool = Warden::Pool::Base.new(5) { |i| i } - pool.fetch(1).should == 1 - pool.fetch(1).should == nil + expect(pool.fetch(1)).to eq 1 + expect(pool.fetch(1)).to eq nil end it "should return nil when not available" do pool = Warden::Pool::Base.new(5) { |i| i } - pool.fetch(10).should == nil + expect(pool.fetch(10)).to eq nil end end @@ -62,9 +62,9 @@ it "should make entry size again" do pool = Warden::Pool::Base.new(0) { |i| i } - pool.size.should == 0 + expect(pool.size).to eq 0 pool.release(0) - pool.size.should == 1 + expect(pool.size).to eq 1 end end end diff --git a/warden/spec/pool/network_spec.rb b/warden/spec/pool/network_spec.rb index 9b8ec81b..c564603c 100644 --- a/warden/spec/pool/network_spec.rb +++ b/warden/spec/pool/network_spec.rb @@ -9,32 +9,32 @@ it "should iterate over IPs" do pool = Warden::Pool::Network.new("127.0.0.0/29") - pool.acquire.should == "127.0.0.0" - pool.acquire.should == "127.0.0.4" - pool.acquire.should be_nil + expect(pool.acquire).to eq "127.0.0.0" + expect(pool.acquire).to eq "127.0.0.4" + expect(pool.acquire).to be_nil end it "should work with different netmasks" do pool = Warden::Pool::Network.new("127.0.0.0/32") - pool.size.should == 0 + expect(pool.size).to eq 0 pool = Warden::Pool::Network.new("127.0.0.0/31") - pool.size.should == 0 + expect(pool.size).to eq 0 pool = Warden::Pool::Network.new("127.0.0.0/30") - pool.size.should == 1 + expect(pool.size).to eq 1 pool = Warden::Pool::Network.new("127.0.0.0/29") - pool.size.should == 2 + expect(pool.size).to eq 2 pool = Warden::Pool::Network.new("127.0.0.0/28") - pool.size.should == 4 + expect(pool.size).to eq 4 end it "should have a netmask" do pool = Warden::Pool::Network.new("127.0.0.0/32") - pool.pooled_netmask.should be_a(Warden::Network::Netmask) + expect(pool.pooled_netmask).to be_a(Warden::Network::Netmask) end it "should default to a proper release delay" do pool = Warden::Pool::Network.new("127.0.0.0/29") - pool.release_delay.should >= 5 + expect(pool.release_delay).to be >= 5 end end @@ -42,7 +42,7 @@ it "should ignore networks that don't belong to the pool" do pool = Warden::Pool::Network.new("127.0.0.0/29") pool.release(Warden::Network::Address.new("10.10.10.10")) - pool.size.should == 2 + expect(pool.size).to eq 2 end end end diff --git a/warden/spec/pool/port_spec.rb b/warden/spec/pool/port_spec.rb index 294f25d6..197b19b3 100644 --- a/warden/spec/pool/port_spec.rb +++ b/warden/spec/pool/port_spec.rb @@ -15,10 +15,10 @@ pool = Warden::Pool::Port.new(61001, 4000) # Check size - pool.size.should == 4000 + expect(pool.size).to eq 4000 # Check first entry - pool.acquire.should == 61001 + expect(pool.acquire).to eq 61001 end end diff --git a/warden/spec/pool/uid_spec.rb b/warden/spec/pool/uid_spec.rb index fe9ef835..26791c68 100644 --- a/warden/spec/pool/uid_spec.rb +++ b/warden/spec/pool/uid_spec.rb @@ -6,7 +6,7 @@ describe Warden::Pool::Uid do before(:each) do - Warden::Pool::Uid.should_receive(:local_uids).and_return([1000, 1001, 1002]) + allow(Warden::Pool::Uid).to receive(:local_uids).and_return([1000, 1001, 1002]) end context "create" do @@ -25,10 +25,10 @@ end.to_not raise_error # Check size - pool.size.should == 5 + expect(pool.size).to eq 5 # Check first entry - pool.acquire.should == 2000 + expect(pool.acquire).to eq 2000 end end @@ -49,7 +49,7 @@ pool = Warden::Pool::Uid.new(2000, 5) pool.release(3000) - pool.size.should == 5 + expect(pool.size).to eq 5 end end end diff --git a/warden/spec/repl/commands_manager_spec.rb b/warden/spec/repl/commands_manager_spec.rb index 17dce92e..fed92b4a 100644 --- a/warden/spec/repl/commands_manager_spec.rb +++ b/warden/spec/repl/commands_manager_spec.rb @@ -11,15 +11,15 @@ expect { described_class.new("%") }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagElementError - error.message.should == "Invalid flag element: '%'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagElementError + expect(error.message).to eq "Invalid flag element: '%'." } expect { described_class.new("0") }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagElementError - error.message.should == "Invalid flag element: '0'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagElementError + expect(error.message).to eq "Invalid flag element: '0'." } end end @@ -27,39 +27,39 @@ describe "#name, #index" do it "should parse the field name and index from a valid flag element string" do obj = described_class.new("field") - obj.name.should == "field" - obj.index.should be_nil + expect(obj.name).to eq "field" + expect(obj.index).to be_nil obj = described_class.new("field[0]") - obj.name.should == "field" - obj.index.should == 0 + expect(obj.name).to eq "field" + expect(obj.index).to eq 0 end end describe "#to_s" do it "should return the string representation" do - described_class.new("field").to_s.should == "field" - described_class.new("field[0]").to_s.should == "field[0]" + expect(described_class.new("field").to_s).to eq "field" + expect(described_class.new("field[0]").to_s).to eq "field[0]" end end describe "#==" do it "should return false for nil" do - (described_class.new("a[0]") == nil).should be_false + expect((described_class.new("a[0]") == nil)).to be false end it "should return false for different class type" do - (described_class.new("a[0]") == Object.new).should be_false + expect((described_class.new("a[0]") == Object.new)).to be false end it "should return false if attributes are different" do condition = (described_class.new("a[0]") == described_class.new("b[1]")) - condition.should be_false + expect(condition).to be false end it "should return true if attribtues are the same" do condition = (described_class.new("a[0]") == described_class.new("a[0]")) - condition.should be_true + expect(condition).to be true end end end @@ -70,8 +70,8 @@ expect { described_class.new("blah") }.to raise_error{ |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: 'blah'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: 'blah'." } end @@ -79,9 +79,9 @@ expect { described_class.new("--blah[0].-$%.foo.bar") }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError msg = "In flag: '--blah[0].-$%.foo.bar', Invalid flag element: '-$%'." - error.message.should == msg + expect(error.message).to eq msg } end end @@ -92,18 +92,18 @@ Warden::Repl::CommandsManager::FlagElement.new("b")] obj = described_class.new("--#{elements[0].to_s}.#{elements[1].to_s}") - obj.respond_to?(:each).should be_true + expect(obj.respond_to?(:each)).to be true index = 0 obj.each do |element| - element.should be_an_instance_of Warden::Repl::CommandsManager::FlagElement - element.should == elements[index] + expect(element).to be_an_instance_of Warden::Repl::CommandsManager::FlagElement + expect(element).to eq elements[index] index += 1 end - obj.respond_to?(:each_with_index).should be_true + expect(obj.respond_to?(:each_with_index)).to be true obj.each_with_index do |element, index| - element.should be_an_instance_of Warden::Repl::CommandsManager::FlagElement - element.should == elements[index] + expect(element).to be_an_instance_of Warden::Repl::CommandsManager::FlagElement + expect(element).to eq elements[index] end end end @@ -119,14 +119,14 @@ describe "#deserialize" do it "should allow global help flag" do - @subject.deserialize(["--help"]).should be_nil - @subject.deserialize(["help"]).should be_nil + expect(@subject.deserialize(["--help"])).to be_nil + expect(@subject.deserialize(["help"])).to be_nil end context "parse valid fields" do before :each do @request = nil - Warden::Protocol::Message::Type.stub(:generate_klass_map). + allow(Warden::Protocol::Message::Type).to receive(:generate_klass_map). with("Request").and_return(Helpers::Repl.test_klass_map) end @@ -140,8 +140,8 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::SimpleTest - @request.field.should == "value" + expect(@request).to be_an_instance_of Helpers::Repl::SimpleTest + expect(@request.field).to eq "value" end it "should parse repeated field" do @@ -151,10 +151,10 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::RepeatedTest - @request.field.size.should == 2 - @request.field[0].should == "value_0" - @request.field[1].should == "value_1" + expect(@request).to be_an_instance_of Helpers::Repl::RepeatedTest + expect(@request.field.size).to eq 2 + expect(@request.field[0]).to eq "value_0" + expect(@request.field[1]).to eq "value_1" end it "should parse nested field" do @@ -163,8 +163,8 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::NestedTest - @request.complex_field.field.should == "value" + expect(@request).to be_an_instance_of Helpers::Repl::NestedTest + expect(@request.complex_field.field).to eq "value" end it "should parse bool field" do @@ -173,8 +173,8 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::BoolTest - @request.field.should be_true + expect(@request).to be_an_instance_of Helpers::Repl::BoolTest + expect(@request.field).to be true end it "should parse enum field" do @@ -183,8 +183,8 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::EnumTest - @request.field.should == Helpers::Repl::EnumTest::Enum::A + expect(@request).to be_an_instance_of Helpers::Repl::EnumTest + expect(@request.field).to eq Helpers::Repl::EnumTest::Enum::A end it "should parse mixed fields" do @@ -194,12 +194,12 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::MixedTest - @request.complex_field.should be_an_instance_of Array - @request.complex_field.size.should == 1 - @request.complex_field[0].should be_an_instance_of Helpers::Repl::SimpleTest - @request.complex_field[0].field.should == "value" - @request.bool_field.should == true + expect(@request).to be_an_instance_of Helpers::Repl::MixedTest + expect(@request.complex_field).to be_an_instance_of Array + expect(@request.complex_field.size).to eq 1 + expect(@request.complex_field[0]).to be_an_instance_of Helpers::Repl::SimpleTest + expect(@request.complex_field[0].field).to eq "value" + expect(@request.bool_field).to eq true end it "should allow overwriting of simple field" do @@ -209,8 +209,8 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::SimpleTest - @request.field.should == "overwrite" + expect(@request).to be_an_instance_of Helpers::Repl::SimpleTest + expect(@request.field).to eq "overwrite" end it "should allow overwriting of repeated field" do @@ -220,9 +220,9 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::RepeatedTest - @request.field.size.should == 1 - @request.field[0].should == "overwrite" + expect(@request).to be_an_instance_of Helpers::Repl::RepeatedTest + expect(@request.field.size).to eq 1 + expect(@request.field[0]).to eq "overwrite" end it "should allow overwriting of nested field" do @@ -232,9 +232,9 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::NestedTest - @request.complex_field.should be_an_instance_of Helpers::Repl::SimpleTest - @request.complex_field.field.should == "overwrite" + expect(@request).to be_an_instance_of Helpers::Repl::NestedTest + expect(@request.complex_field).to be_an_instance_of Helpers::Repl::SimpleTest + expect(@request.complex_field.field).to eq "overwrite" end it "should allow overwriting of bool field" do @@ -244,8 +244,8 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::BoolTest - @request.field.should be_true + expect(@request).to be_an_instance_of Helpers::Repl::BoolTest + expect(@request.field).to be true end it "should allow overwriting of enum field" do @@ -255,8 +255,8 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::EnumTest - @request.field.should == Helpers::Repl::EnumTest::Enum::B + expect(@request).to be_an_instance_of Helpers::Repl::EnumTest + expect(@request.field).to eq Helpers::Repl::EnumTest::Enum::B end it "should work for a different field delimiter" do @@ -265,8 +265,8 @@ @request = @subject.deserialize(args, ":") - @request.should be_an_instance_of Helpers::Repl::NestedTest - @request.complex_field.field.should == "value" + expect(@request).to be_an_instance_of Helpers::Repl::NestedTest + expect(@request.complex_field.field).to eq "value" end it "should not treat -- in the middle as a field" do @@ -275,14 +275,14 @@ @request = @subject.deserialize(args) - @request.should be_an_instance_of Helpers::Repl::SimpleTest - @request.field.should == "ab --help" + expect(@request).to be_an_instance_of Helpers::Repl::SimpleTest + expect(@request.field).to eq "ab --help" end end context "reject invalid commands and fields" do before :each do - Warden::Protocol::Message::Type.stub(:generate_klass_map). + allow(Warden::Protocol::Message::Type).to receive(:generate_klass_map). with("Request").and_return(Helpers::Repl.test_klass_map) end @@ -292,8 +292,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::CommandError - error.message.should == "Command: 'absent_command' is non-existent." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::CommandError + expect(error.message).to eq "Command: 'absent_command' is non-existent." } end @@ -304,8 +304,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: 'help'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: 'help'." } end @@ -315,8 +315,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: 'field'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: 'field'." } args = ["simple_test", @@ -324,8 +324,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: '--field'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: '--field'." } args = ["simple_test", @@ -333,9 +333,9 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError msg = "In flag: '--bad_field', the field: 'bad_field' is invalid." - error.message.should == msg + expect(error.message).to eq msg } end @@ -345,8 +345,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: 'field'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: 'field'." } args = ["repeated_test", @@ -354,9 +354,9 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError msg = "In flag: '--field', the field: 'field' is not indexed." - error.message.should == msg + expect(error.message).to eq msg } args = ["repeated_test", @@ -364,10 +364,10 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError msg = "In flag: '--field[1]', the field: 'field[1]' is not indexed" msg << " correctly." - error.message.should == msg + expect(error.message).to eq msg } args = ["repeated_test", @@ -375,10 +375,10 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError msg = "In flag: '--field[bad_index]'," msg << " Invalid flag element: 'field[bad_index]'." - error.message.should == msg + expect(error.message).to eq msg } args = ["repeated_test", @@ -387,9 +387,9 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError msg = "In flag: '--field[-1]', Invalid flag element: 'field[-1]'." - error.message.should == msg + expect(error.message).to eq msg } args = ["repeated_test", @@ -398,10 +398,10 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError msg = "In flag: '--field[2]'," msg << " the field: 'field[2]' is not indexed correctly." - error.message.should == msg + expect(error.message).to eq msg } end @@ -411,8 +411,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: 'complex_field'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: 'complex_field'." } args = ["nested_test", @@ -420,8 +420,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: '--complex_field'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: '--complex_field'." } args = ["nested_test", @@ -429,10 +429,10 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError msg = "In flag: '--complex_field.absent_field'," msg << " the field: 'absent_field' is invalid." - error.message.should == msg + expect(error.message).to eq msg } args = ["nested_test", @@ -440,8 +440,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: '--complex_field.field'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: '--complex_field.field'." } end @@ -451,8 +451,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: 'field'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: 'field'." } args = ["bool_test", @@ -460,8 +460,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: 'value'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: 'value'." } end @@ -471,8 +471,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: 'field'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: 'field'." } args = ["enum_test", @@ -480,8 +480,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError - error.message.should == "Invalid flag: '--field'." + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error.message).to eq "Invalid flag: '--field'." } args = ["enum_test", @@ -489,9 +489,9 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::FlagError + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::FlagError msg = "In flag: '--bad_field', the field: 'bad_field' is invalid." - error.message.should == msg + expect(error.message).to eq msg } end @@ -501,8 +501,8 @@ expect { @subject.deserialize(args) }.to raise_error { |error| - error.should be_an_instance_of Warden::Repl::CommandsManager::CommandError - error.message.should == "invalid value for Integer(): \"blah\"" + expect(error).to be_an_instance_of Warden::Repl::CommandsManager::CommandError + expect(error.message).to eq "invalid value for Integer(): \"blah\"" } end end @@ -510,9 +510,9 @@ context "generate help" do before(:each) do - Warden::Protocol::Message::Type.stub(:generate_klass_map). + allow(Warden::Protocol::Message::Type).to receive(:generate_klass_map). with("Request").and_return(Helpers::Repl.test_klass_map) - @subject.stub(:command_descriptions). + allow(@subject).to receive(:command_descriptions). and_return(Helpers::Repl.test_description_map) end @@ -522,8 +522,8 @@ help = @subject.deserialize(args) - help.should be_an_instance_of Hash - help.should == { + expect(help).to be_an_instance_of Hash + expect(help).to eq({ :simple_fields_help_test => { :description => "Test generation of help for simple fields.", :required => { @@ -537,7 +537,7 @@ :rep_field => "--rep_field[index] (uint32) # array", } } - } + }) end it "should generate help for a command with nested field(s)" do @@ -546,7 +546,7 @@ help = @subject.deserialize(args) - help.should be_an_instance_of Hash + expect(help).to be_an_instance_of Hash nested_field_help = { :req_complex_field => { @@ -564,12 +564,12 @@ } } - help.should == { + expect(help).to eq({ :nested_fields_help_test => { :description => "Test generation of help for nested field.", :required => nested_field_help } - } + }) end it "should work for a specified field delimiter" do @@ -577,7 +577,7 @@ "--help"] help = @subject.deserialize(args, ":") - help.should be_an_instance_of Hash + expect(help).to be_an_instance_of Hash nested_field_help = { :req_complex_field => { @@ -595,12 +595,12 @@ } } - help.should == { + expect(help).to eq({ :nested_fields_help_test => { :description => "Test generation of help for nested field.", :required => nested_field_help } - } + }) end end end @@ -611,19 +611,19 @@ pb_handle = Helpers::Repl::SimpleTest.new pb_handle.field = "field" hash = @subject.serialize(pb_handle) - hash.should == { + expect(hash).to eq({ "field" => "field", - } + }) end it "should serialize repeated field" do pb_handle = Helpers::Repl::RepeatedTest.new pb_handle.field = ["value_0", "value_1"] hash = @subject.serialize(pb_handle) - hash.should == { + expect(hash).to eq({ "field[0]" => "value_0", "field[1]" => "value_1", - } + }) end it "should serialize nested field" do @@ -631,27 +631,27 @@ pb_handle.complex_field = Helpers::Repl::SimpleTest.new pb_handle.complex_field.field = "field" hash = @subject.serialize(pb_handle) - hash.should == { + expect(hash).to eq({ "complex_field.field" => "field", - } + }) end it "should serialize bool field" do pb_handle = Helpers::Repl::BoolTest.new pb_handle.field = true hash = @subject.serialize(pb_handle) - hash.should == { + expect(hash).to eq({ "field" => "true", - } + }) end it "should serialize enum field" do pb_handle = Helpers::Repl::EnumTest.new pb_handle.field = Helpers::Repl::EnumTest::Enum::A hash = @subject.serialize(pb_handle) - hash.should == { + expect(hash).to eq({ "field" => "A", - } + }) end end @@ -664,13 +664,13 @@ @subject.serialize(pb_handle) }.to raise_error{ |error| err_type = Warden::Repl::CommandsManager::SerializationError - error.should be_an_instance_of err_type + expect(error).to be_an_instance_of err_type msg = "Cannot serialize enum field: field." msg << " Duplicate constants defined in module:" msg << " #{Helpers::Repl::BadEnumTest::BadEnum}." - error.message.should == msg + expect(error.message).to eq msg } end end @@ -685,12 +685,12 @@ target = spawn_command.send(field.name) source = run_command.send(field.name) - target.should == source + expect(target).to eq source if target - target.object_id.should_not == source.object_id + expect(target.object_id).to_not eq source.object_id else - source.should be_nil + expect(source).to be_nil end end end @@ -705,9 +705,9 @@ stream_command = @subject.generate_stream_command(spawn_request, spawn_response) handle = stream_command.handle - handle.should == spawn_request.handle - handle.object_id.should_not == spawn_request.handle.object_id - stream_command.job_id.should == spawn_response.job_id + expect(handle).to eq spawn_request.handle + expect(handle.object_id).to_not eq spawn_request.handle.object_id + expect(stream_command.job_id).to eq spawn_response.job_id end end end diff --git a/warden/spec/repl/repl_v2_runner_spec.rb b/warden/spec/repl/repl_v2_runner_spec.rb index 9ae8c61d..7b0b4564 100644 --- a/warden/spec/repl/repl_v2_runner_spec.rb +++ b/warden/spec/repl/repl_v2_runner_spec.rb @@ -7,21 +7,21 @@ context "parse global arguments" do it "should parse global arguments" do repl = double("repl") - repl.should_receive(:start).once.and_return(0) + allow(repl).to receive(:start).once.and_return(0) expected_options = { :trace => true, :socket_path => "/foo/bar", :exit_on_error => true, } - Warden::Repl::Repl.should_receive(:new).once.with(expected_options). + allow(Warden::Repl::Repl).to receive(:new).once.with(expected_options). and_return(repl) expect do described_class.run(["--trace", "--exit_on_error", "--socket", "/foo/bar"]) end.to raise_error(SystemExit) do |error| - error.status.should == 0 + expect(error.status).to eq 0 end end @@ -37,17 +37,17 @@ it "should print help" do received_output = "" - STDOUT.should_receive(:write).any_number_of_times do |arg| + allow(STDOUT).to receive(:write) do |arg| received_output << arg end expect { described_class.run(["--help"]) }.to raise_error(SystemExit) { |error| - error.status.should == 0 + expect(error.status).to eq 0 } - received_output.should =~ /^Usage:.*/ + expect(received_output).to match /^Usage:.*/ end it "should raise error if the delimiter separating global args and command args is specified more than once" do @@ -60,29 +60,29 @@ context "start interactive repl" do it "should set trap for SIGINT signal" do - described_class.should_receive(:trap).once.and_yield - STDERR.should_receive(:write).once.with("\n\nExiting...\n") + allow(described_class).to receive(:trap).once.and_yield + allow(STDERR).to receive(:write).once.with("\n\nExiting...\n") repl = double("repl") - Warden::Repl::Repl.should_receive(:new).once.with({}).and_return(repl) + allow(Warden::Repl::Repl).to receive(:new).once.with({}).and_return(repl) expect { described_class.run }.to raise_error(SystemExit) { |error| - error.status.should == 0 + expect(error.status).to eq 0 } end it "should start interactive repl" do repl = double("repl") - repl.should_receive(:start).once.and_return(0) + allow(repl).to receive(:start).once.and_return(0) - Warden::Repl::Repl.should_receive(:new).once.with({}).and_return(repl) + allow(Warden::Repl::Repl).to receive(:new).once.with({}).and_return(repl) expect do described_class.run end.to raise_error(SystemExit) do |error| - error.status.should == 0 + expect(error.status).to eq 0 end end end @@ -90,48 +90,48 @@ context "execute commands non-interactively" do it "should write output of command to stdout and exit with exit status of the command" do repl = double("repl") - repl.should_receive(:process_command).once.with(["command", "--arg"]). + allow(repl).to receive(:process_command).once.with(["command", "--arg"]). and_return({ :result => "result", :exit_status => 2 }) - Warden::Repl::Repl.should_receive(:new).once.with({}).and_return(repl) + allow(Warden::Repl::Repl).to receive(:new).once.with({}).and_return(repl) received_output = "" - STDOUT.should_receive(:write).any_number_of_times do |arg| + allow(STDOUT).to receive(:write) do |arg| received_output << arg end expect { described_class.run(["--", "command", "--arg"]) }.to raise_error(SystemExit) { |error| - error.status.should == 2 + expect(error.status).to eq 2 } - received_output.should == "result" + expect(received_output).to eq "result" end it "should write stack back trace of command error to stderr and exit with status 0" do repl = double("repl") ce = Warden::Repl::CommandsManager::CommandError.new("command error") - repl.should_receive(:process_command).once.with(["command", "--arg"]). + allow(repl).to receive(:process_command).once.with(["command", "--arg"]). and_raise(ce) - Warden::Repl::Repl.should_receive(:new).once.with({}).and_return(repl) + allow(Warden::Repl::Repl).to receive(:new).once.with({}).and_return(repl) received_err = "" - STDERR.should_receive(:write).any_number_of_times do |arg| + allow(STDERR).to receive(:write) do |arg| received_err << arg end expect { described_class.run(["--", "command", "--arg"]) }.to raise_error(SystemExit) { |error| - error.status.should == 0 + expect(error.status).to eq 0 } expected_err = "#{ce}\n" ce.backtrace.each { |err| expected_err << "#{err}\n" } - received_err.should == expected_err + expect(received_err).to eq expected_err end end end diff --git a/warden/spec/repl/repl_v2_spec.rb b/warden/spec/repl/repl_v2_spec.rb index 9956f444..ed657509 100644 --- a/warden/spec/repl/repl_v2_spec.rb +++ b/warden/spec/repl/repl_v2_spec.rb @@ -8,52 +8,52 @@ describe "#start" do before :each do - Readline.should_receive(:completion_append_character=).once - Readline.should_receive(:completion_proc=).once + allow(Readline).to receive(:completion_append_character=).once + allow(Readline).to receive(:completion_proc=).once @client = double("warden client") end context "connect to the server" do before :each do - Readline.should_receive(:readline).once.with('warden> ', true) + allow(Readline).to receive(:readline).once.with('warden> ', true) .and_return(nil) end it "through the default socket path if none is specified" do - @client.should_receive(:connect).once - @client.should_receive(:connected?).once.and_return(false) + allow(@client).to receive(:connect).once + allow(@client).to receive(:connected?).once.and_return(false) - Warden::Client.should_receive(:new).once.with("/tmp/warden.sock") + allow(Warden::Client).to receive(:new).once.with("/tmp/warden.sock") .and_return(@client) repl = described_class.new - repl.should_receive(:restore_history).once + allow(repl).to receive(:restore_history).once repl.start end it "through the specified socket path" do socket_path = "socket_path" - @client.should_receive(:connect).once - @client.should_receive(:connected?).once.and_return(false) + allow(@client).to receive(:connect).once + allow(@client).to receive(:connected?).once.and_return(false) - Warden::Client.should_receive(:new).once.with(socket_path) + allow(Warden::Client).to receive(:new).once.with(socket_path) .and_return(@client) repl = described_class.new(:socket_path => socket_path) - repl.should_receive(:restore_history).once + allow(repl).to receive(:restore_history).once repl.start end it "not reconnect to the server if already connected" do - @client.should_receive(:connected?).once.and_return(true) + allow(@client).to receive(:connected?).once.and_return(true) - Warden::Client.should_receive(:new).once.with("/tmp/warden.sock") + allow(Warden::Client).to receive(:new).once.with("/tmp/warden.sock") .and_return(@client) repl= described_class.new - repl.should_receive(:restore_history).once + allow(repl).to receive(:restore_history).once repl.start end end @@ -61,33 +61,33 @@ context "read input, write errors" do before :each do @command = "simple_test --field field" - Readline.should_receive(:readline).once.with('warden> ', true) + allow(Readline).to receive(:readline).once.with('warden> ', true) .and_return(@command, nil) - @client.should_receive(:connected?).once.and_return(true) - Warden::Client.should_receive(:new).once.with("/tmp/warden.sock") + allow(@client).to receive(:connected?).once.and_return(true) + allow(Warden::Client).to receive(:new).once.with("/tmp/warden.sock") .and_return(@client) @repl = described_class.new - @repl.should_receive(:restore_history).once.and_return(nil) + allow(@repl).to receive(:restore_history).once.and_return(nil) end it "should read commands from stdin" do - @repl.should_receive(:process_line).once.with(@command) + allow(@repl).to receive(:process_line).once.with(@command) .and_return({:result => "result"}) - STDOUT.should_receive(:write).with("result").once + allow(STDOUT).to receive(:write).with("result").once - @repl.should_receive(:save_history).once.and_return(nil) + allow(@repl).to receive(:save_history).once.and_return(nil) @repl.start end it "should write command error messages to stderr" do ce = Warden::Repl::CommandsManager::CommandError.new("command error") - @repl.should_receive(:process_line).once.with(@command) + allow(@repl).to receive(:process_line).once.with(@command) .and_raise(ce) - STDERR.should_receive(:write).with("#{ce.message}\n").once + allow(STDERR).to receive(:write).with("#{ce.message}\n").once @repl.start end @@ -97,96 +97,96 @@ before :each do @command = "simple_test --field field" - @client.should_receive(:connected?).once.and_return(true) - Warden::Client.should_receive(:new).once.with("/tmp/warden.sock") + allow(@client).to receive(:connected?).once.and_return(true) + allow(Warden::Client).to receive(:new).once.with("/tmp/warden.sock") .and_return(@client) - Readline.should_receive(:readline).with('warden> ', true) + allow(Readline).to receive(:readline).with('warden> ', true) .and_return(@command) @repl = described_class.new(:exit_on_error => true) - @repl.should_receive(:restore_history).once.and_return(nil) + allow(@repl).to receive(:restore_history).once.and_return(nil) end it "should return the exit status of the first failed command" do # Injecting non-zero exit status below in the mock - @repl.should_receive(:process_line).once.with(@command) + allow(@repl).to receive(:process_line).once.with(@command) .and_return({:exit_status => 2, :result => "result"}) - STDOUT.should_receive(:write).with("result").once + allow(STDOUT).to receive(:write).with("result").once - @repl.should_receive(:save_history).once.and_return(nil) - @repl.start.should == 2 + allow(@repl).to receive(:save_history).once.and_return(nil) + expect(@repl.start).to eq 2 end it "should write command error messages to stderr and return 0" do ce = Warden::Repl::CommandsManager::CommandError.new("command error") - @repl.should_receive(:process_line).once.with(@command) + allow(@repl).to receive(:process_line).once.with(@command) .and_raise(ce) - STDERR.should_receive(:write).with("#{ce.message}\n").once + allow(STDERR).to receive(:write).with("#{ce.message}\n").once - @repl.start.should == 0 + expect(@repl.start).to eq 0 end end context "save, restore history" do before :each do - @client.should_receive(:connected?).once.and_return(true) - Warden::Client.should_receive(:new).once.with("/tmp/warden.sock") + allow(@client).to receive(:connected?).once.and_return(true) + allow(Warden::Client).to receive(:new).once.with("/tmp/warden.sock") .and_return(@client) @repl = described_class.new(:history_path => "history_path") end it "should save the command history" do - Readline.should_receive(:readline).once.with('warden> ', true) + allow(Readline).to receive(:readline).once.with('warden> ', true) .and_return("simple_test --field field", nil) history = double("history") - Readline::HISTORY.should_receive(:to_a).and_return(history) - history.should_receive(:to_json).once.and_return('"["test"]"') + allow(Readline::HISTORY).to receive(:to_a).and_return(history) + allow(history).to receive(:to_json).once.and_return('"["test"]"') command = "simple_test --field field" - @repl.should_receive(:process_line).once.with(command) + allow(@repl).to receive(:process_line).once.with(command) .and_return({:result => "result"}) - @repl.should_receive(:restore_history).and_return(nil) + allow(@repl).to receive(:restore_history).and_return(nil) file = double("history file") - file.should_receive(:write).once.with('"["test"]"') + allow(file).to receive(:write).once.with('"["test"]"') - @repl.should_receive(:open).once.with("history_path", "w+") + allow(@repl).to receive(:open).once.with("history_path", "w+") .and_yield(file) - STDOUT.should_receive(:write).with("result").once + allow(STDOUT).to receive(:write).with("result").once @repl.start end it "should not restore the command history when the file is absent" do - Readline.should_receive(:readline).once.with('warden> ', true) + allow(Readline).to receive(:readline).once.with('warden> ', true) .and_return(nil) - File.should_receive(:exists?).once.with("history_path") + allow(File).to receive(:exists?).once.with("history_path") .and_return(false) @repl.start end it "should restore the command history" do - Readline.should_receive(:readline).once.with('warden> ', true) + allow(Readline).to receive(:readline).once.with('warden> ', true) .and_return(nil) - File.should_receive(:exists?).once.with("history_path") + allow(File).to receive(:exists?).once.with("history_path") .and_return(true) - Readline::HISTORY.should_receive(:push).once.with("test") + allow(Readline::HISTORY).to receive(:push).once.with("test") .and_return(nil) file = double("history file") - file.should_receive(:read).once.and_return('["test"]') + allow(file).to receive(:read).once.and_return('["test"]') - @repl.should_receive(:open).once.with("history_path", "r") + allow(@repl).to receive(:open).once.with("history_path", "r") .and_yield(file) @repl.start end @@ -196,13 +196,13 @@ describe "#process_line" do before :each do @client = double("warden client") - Warden::Client.should_receive(:new).once.with("/tmp/warden.sock") + allow(Warden::Client).to receive(:new).once.with("/tmp/warden.sock") .and_return(@client) end context "handle run command" do before :each do - Warden::Protocol::Message::Type.stub(:generate_klass_map) + allow(Warden::Protocol::Message::Type).to receive(:generate_klass_map) .with("Request").and_return({1 => Warden::Protocol::RunRequest}) end @@ -231,13 +231,13 @@ stream_exit = Warden::Protocol::StreamResponse.new stream_exit.exit_status = 1 - @client.should_receive(:connected?).once.and_return(true) - @client.should_receive(:call).once.with(spawn_request) + allow(@client).to receive(:connected?).once.and_return(true) + allow(@client).to receive(:call).once.with(spawn_request) .and_return(spawn_response) - @client.should_receive(:stream).once.with(stream_request) + allow(@client).to receive(:stream).once.with(stream_request) .and_yield(stream_data).and_return(stream_exit) - STDOUT.should_receive(:write).once.with("stdout") + allow(STDOUT).to receive(:write).once.with("stdout") repl = described_class.new command_info = repl.process_line("run --handle handle --script script --log_tag some_log_tag") @@ -245,7 +245,7 @@ it "should generate right description for run command in global help" do repl = described_class.new - repl.stub(:command_descriptions).and_return do + allow(repl).to receive(:command_descriptions) do {"run" => described_class.run_command_description} end @@ -259,21 +259,19 @@ expected << "Use --help with each command for more information." expected << "\n" - command_info[:result].should == expected + expect(command_info[:result]).to eq expected end it "should generate right description for run command help" do repl = described_class.new command_info = repl.process_line("run --help") - command_info[:result] - .index("description: #{described_class.run_command_description}"). - should be > 0 + expect(command_info[:result].index("description: #{described_class.run_command_description}")).to be > 0 end end context "handle other commands" do before :each do - Warden::Protocol::Message::Type.stub(:generate_klass_map) + allow(Warden::Protocol::Message::Type).to receive(:generate_klass_map) .with("Request").and_return(Helpers::Repl.test_klass_map) end @@ -281,34 +279,34 @@ request = response = Helpers::Repl::SimpleTest.new request.field = "field" - @client.should_receive(:connected?).once.and_return(true) - @client.should_receive(:call).once.with(request).and_return(response) + allow(@client).to receive(:connected?).once.and_return(true) + allow(@client).to receive(:call).once.with(request).and_return(response) repl = described_class.new(:trace => true) command_info = repl.process_line("simple_test --field field") expected = "+ simple_test --field field\nfield : field\n" - command_info.keys.should == [:result] - command_info[:result].should =~ /^\+ simple_test --field field\n.*/ + expect(command_info.keys).to eq [:result] + expect(command_info[:result]).to match /^\+ simple_test --field field\n.*/ end it "should serialize response from warden server" do request = response = Helpers::Repl::SimpleTest.new request.field = "field" - @client.should_receive(:connected?).once.and_return(true) - @client.should_receive(:call).once.with(request).and_return(response) + allow(@client).to receive(:connected?).once.and_return(true) + allow(@client).to receive(:call).once.with(request).and_return(response) repl = described_class.new command_info = repl.process_line("simple_test --field field") expected = "+ simple_test --field field\nfield : field\n" - command_info.should == {:result => "field : field\n"} + expect(command_info).to eq({:result => "field : field\n"}) end it "should generate prettified global help" do repl = described_class.new - repl.stub(:command_descriptions).and_return(Helpers::Repl.test_description_map) + allow(repl).to receive(:command_descriptions).and_return(Helpers::Repl.test_description_map) command_info = repl.process_line("--help") @@ -323,12 +321,12 @@ expected << "Use --help with each command for more information." expected << "\n" - command_info[:result].should == expected + expect(command_info[:result]).to eq expected end it "should generate prettified command help for simple command" do repl = described_class.new - repl.stub(:command_descriptions).and_return(Helpers::Repl.test_description_map) + allow(repl).to receive(:command_descriptions).and_return(Helpers::Repl.test_description_map) command_info = repl.process_line("simple_test --help") @@ -339,12 +337,12 @@ expected << "[options] can be one of the following:\n\n" expected << "\t--field (string) # required\n" - command_info[:result].should == expected + expect(command_info[:result]).to eq expected end it "should generate prettified command help for complex command" do repl = described_class.new - repl.stub(:command_descriptions).and_return(Helpers::Repl.test_description_map) + allow(repl).to receive(:command_descriptions).and_return(Helpers::Repl.test_description_map) command_info = repl.process_line("mixed_test --help") @@ -357,7 +355,7 @@ expected << "\t--complex_field[index] # array\n" expected << "\t\t.field (string) # required\n" - command_info[:result].should == expected + expect(command_info[:result]).to eq expected end end end diff --git a/warden/spec/spec_helper.rb b/warden/spec/spec_helper.rb index c95e347d..edcd816c 100644 --- a/warden/spec/spec_helper.rb +++ b/warden/spec/spec_helper.rb @@ -34,7 +34,7 @@ def done ::EM.next_tick { # Assert something to show a spec-pass - :done.should == :done + expect(:done).to eq :done ::EM.stop_event_loop } end diff --git a/warden/spec/support/examples/drain.rb b/warden/spec/support/examples/drain.rb index cb3c722f..c52fa91e 100644 --- a/warden/spec/support/examples/drain.rb +++ b/warden/spec/support/examples/drain.rb @@ -16,7 +16,7 @@ def warden_running? sleep 0.05 end - warden_running?.should be_false + expect(warden_running?).to be_falsey end it "should break connections that are inactive" do @@ -26,26 +26,30 @@ def warden_running? expect do client.destroy(:handle => handle) - end.to raise_error + end.to raise_error Errno::EPIPE end it "should break link requests" do - check_request_broken do + check_request_broken do |handle| resp = client.spawn(:handle => handle, :script => "sleep 1000") client.link(:handle => handle, :job_id => resp.job_id) end end it "should break run requests" do - check_request_broken do + check_request_broken do |handle| client.run(:handle => handle, :script => "sleep 1000") end end it "should break stream requests" do - check_request_broken do + check_request_broken do |handle| resp = client.spawn(:handle => handle, :script => "sleep 1000") - client.stream(:handle => handle, :job_id => resp.job_id) + + stream_request = Warden::Protocol::StreamRequest.new + stream_request.handle = handle + stream_request.job_id = resp.job_id + client.stream(stream_request) end end @@ -55,7 +59,7 @@ def warden_running? drain - File.exist?(snapshot_path).should be_true + expect(File.exist?(snapshot_path)).to be true end it "should recreate existing containers" do @@ -69,7 +73,7 @@ def warden_running? new_client = create_client [active_handle, stopped_handle].zip(["active", "stopped"]).each do |h, state| - new_client.info(:handle => h).state.should == state + expect(new_client.info(:handle => h).state).to eq state end end @@ -90,7 +94,7 @@ def warden_running? start_warden c = create_client - c.info(:handle => handle).container_path.should == new_path + expect(c.info(:handle => handle).container_path).to eq new_path end it "should not place existing containers networks back into the pool" do @@ -99,7 +103,7 @@ def warden_running? drain_and_restart # Sort of a hack, relies on the fact that handles are encoded ips - create_client.create.handle.should_not == old_handle + expect(create_client.create.handle).to_not eq old_handle end it "should not place existing containers ports back into the pool" do @@ -110,7 +114,7 @@ def warden_running? c = create_client h = c.create.handle - c.net_in(:handle => h).host_port.should == (old_port + 1) + expect(c.net_in(:handle => h).host_port).to eq (old_port + 1) end @@ -125,7 +129,7 @@ def warden_running? c = create_client h = c.create.handle - get_uid(c, h).should == (old_uid + 1) + expect(get_uid(c, h)).to eq (old_uid + 1) end describe "jobs that stay alive over a restart" do @@ -168,11 +172,11 @@ def spawn_job start = Time.now link_resp = c.link(:handle => @handle, :job_id => job_id) elapsed = Time.now - start - link_resp.exit_status.should == exp_status - link_resp.stdout.should == exp_stdout + expect(link_resp.exit_status).to eq exp_status + expect(link_resp.stdout).to eq exp_stdout # Check command was still running - elapsed.should be > 1 + expect(elapsed).to be > 1 end it "should allow streaming" do @@ -184,11 +188,11 @@ def spawn_job start = Time.now streams = read_streams(c, @handle, job_id) elapsed = Time.now - start - streams.size.should == 1 - streams["stdout"].should == exp_stdout + expect(streams.size).to eq 1 + expect(streams["stdout"]).to eq exp_stdout # Check command was still running - elapsed.should be > 1 + expect(elapsed).to be > 1 end context "and their output is discarded" do @@ -202,10 +206,10 @@ def spawn_job streams = read_streams(c, @handle, job_id) elapsed = Time.now - start - streams.should be_empty + expect(streams).to be_empty # Check command was still running - elapsed.should be > 1 + expect(elapsed).to be > 1 end end @@ -304,9 +308,9 @@ def received_messages(num) c = create_client link_response = c.link(:handle => @handle, :job_id => @job_id) - link_response.stdout.should == "" - link_response.stderr.should == "" - link_response.exit_status.should == 2 + expect(link_response.stdout).to eq "" + expect(link_response.stderr).to eq "" + expect(link_response.exit_status).to eq 2 end describe "grace time" do @@ -324,7 +328,7 @@ def received_messages(num) new_client = create_client sleep 1.1 - expect{ new_client.info(:handle => handle) }.to_not raise_error(/unknown handle/) + expect{ new_client.info(:handle => handle) }.to_not raise_error end end end diff --git a/warden/spec/support/examples/file_transfer.rb b/warden/spec/support/examples/file_transfer.rb index 74548331..62ee88fd 100644 --- a/warden/spec/support/examples/file_transfer.rb +++ b/warden/spec/support/examples/file_transfer.rb @@ -13,35 +13,35 @@ def path_in_container(path) def run(script) response = client.run(:handle => handle, :script => script) - response.should be_ok + expect(response).to be_ok response end def copy_in(options) response = client.copy_in(options.merge(:handle => handle)) - response.should be_ok + expect(response).to be_ok response end def copy_out(options) response = client.copy_out(options.merge(:handle => handle)) - response.should be_ok + expect(response).to be_ok response end def create_file_in_container(path, contents, mode=nil) # Create the directory that will house the file response = run "mkdir -p #{path_in_container(File.dirname(path))}" - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 # Create the file response = run "echo -n #{contents} > #{path_in_container(path)}" - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 # Set permissions if mode response = run "chmod #{mode} #{path_in_container(path)}" - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 end end @@ -60,10 +60,10 @@ def create_file_in_container(path, contents, mode=nil) File.open(@sentinel_path, 'w+') {|f| f.write(@sentinel_contents) } @sentinel_sym_link_path = File.join(@sentinel_dir, 'sentinel_sym_link') - system("ln -s #{@sentinel_path} #{@sentinel_sym_link_path}").should be_true + expect(system("ln -s #{@sentinel_path} #{@sentinel_sym_link_path}")).to be true @sentinel_hard_link_path = File.join(@sentinel_dir, 'sentinel_hard_link') - system("ln #{@sentinel_path} #{@sentinel_hard_link_path}").should be_true + expect(system("ln #{@sentinel_path} #{@sentinel_hard_link_path}")).to be true @relative_sentinel_path = "sentinel_root/sentinel" end @@ -79,8 +79,8 @@ def create_file_in_container(path, contents, mode=nil) c_path = path_in_container(File.join("/tmp", @relative_sentinel_path)) response = run "cat #{c_path}" - response.exit_status.should == 0 - response.stdout.should == @sentinel_contents + expect(response.exit_status).to eq 0 + expect(response.stdout).to eq @sentinel_contents end it "should allow files to be copied out" do @@ -90,7 +90,7 @@ def create_file_in_container(path, contents, mode=nil) :src_path => "/tmp/sentinel_root", :dst_path => @outdir - File.read(File.join(@outdir, @relative_sentinel_path)).should == @sentinel_contents + expect(File.read(File.join(@outdir, @relative_sentinel_path))).to eq @sentinel_contents end it "should preserve file permissions" do @@ -102,8 +102,8 @@ def create_file_in_container(path, contents, mode=nil) c_path = path_in_container(File.join("/tmp", @relative_sentinel_path)) response = run "stat -c %a #{c_path}" - response.exit_status.should == 0 - response.stdout.chomp.should == "755" + expect(response.exit_status).to eq 0 + expect(response.stdout.chomp).to eq "755" create_file_in_container("/tmp/sentinel_root/sentinel", @sentinel_contents) @@ -112,14 +112,14 @@ def create_file_in_container(path, contents, mode=nil) :dst_path => @outdir stats = File.stat(File.join(@outdir, @relative_sentinel_path)) - stats.mode.should == 33261 + expect(stats.mode).to eq 33261 end it "should preserve symlinks" do # Set up identical dir in container to house the copy c_sentinel_dir = path_in_container(@tmpdir) response = run "mkdir -p #{c_sentinel_dir}" - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 copy_in \ :src_path => @sentinel_dir, @@ -127,15 +127,15 @@ def create_file_in_container(path, contents, mode=nil) c_link_path = path_in_container(@sentinel_sym_link_path) response = run "stat -c %F #{c_link_path}" - response.exit_status.should == 0 - response.stdout.chomp.should == "symbolic link" + expect(response.exit_status).to eq 0 + expect(response.stdout.chomp).to eq "symbolic link" end it "should materialize hardlinks" do # Set up identical dir in container to house the copy c_sentinel_dir = path_in_container(@tmpdir) response = run "mkdir -p #{c_sentinel_dir}" - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 copy_in \ :src_path => @sentinel_dir, @@ -144,12 +144,12 @@ def create_file_in_container(path, contents, mode=nil) # No hardlinks in container c_sentinel_dir = path_in_container(@sentinel_dir) response = run "find #{c_sentinel_dir} -xdev -samefile sentinel" - response.exit_status.should == 1 + expect(response.exit_status).to eq 1 # File should be materialized c_hardlink_path = path_in_container(@sentinel_hard_link_path) response = run "cat #{c_hardlink_path}" - response.exit_status.should == 0 - response.stdout.chomp.should == @sentinel_contents + expect(response.exit_status).to eq 0 + expect(response.stdout.chomp).to eq @sentinel_contents end end diff --git a/warden/spec/support/examples/info.rb b/warden/spec/support/examples/info.rb index 39ead5f5..7cf15fe6 100644 --- a/warden/spec/support/examples/info.rb +++ b/warden/spec/support/examples/info.rb @@ -9,7 +9,7 @@ it "should respond to an info request" do response = client.info(:handle => handle) - response.state.should == "active" - response.container_path.should_not be_nil + expect(response.state).to eq "active" + expect(response.container_path).to_not be_nil end end diff --git a/warden/spec/support/examples/lifecycle.rb b/warden/spec/support/examples/lifecycle.rb index 9bfe823e..71e2984a 100644 --- a/warden/spec/support/examples/lifecycle.rb +++ b/warden/spec/support/examples/lifecycle.rb @@ -4,30 +4,30 @@ module Warden::Protocol shared_examples "lifecycle" do it "should allow to create a container" do response = client.create - response.handle.should_not be_nil + expect(response.handle).to_not be_nil end it "should allow to create a container with a custom handle" do response = client.create(:handle => "test_handle") - response.handle.should == "test_handle" + expect(response.handle).to eq "test_handle" end it "should allow to create a container with a custom non-ASCII handle" do response = client.create(:handle => "\302\202") - response.handle.should eq "\302\202" + expect(response.handle).to eq "\302\202" end it "should allow to use a container created with a custom handle" do response = client.create(:handle => "test_handle") - response.handle.should == "test_handle" + expect(response.handle).to eq "test_handle" info = client.info(:handle => "test_handle") - info.should_not be_nil + expect(info).to_not be_nil end it "should not allow to recreate a container that already exists" do response = client.create(:handle => "test_handle") - response.handle.should == "test_handle" + expect(response.handle).to eq "test_handle" expect do response = client.create(:handle => "test_handle") end.to raise_error(/container with handle: test_handle already exists/) @@ -74,9 +74,9 @@ module Warden::Protocol stream_client.write(Warden::Protocol::StreamRequest.new(:handle => handle, :job_id => @job_id)) response = stream_client.read - response.name.should == "stdout" - response.data.should == "x\n" - response.exit_status.should == nil + expect(response.name).to eq "stdout" + expect(response.data).to eq "x\n" + expect(response.exit_status).to eq nil stream_client.disconnect end @@ -89,7 +89,7 @@ module Warden::Protocol # Test that exit status is returned (because of SIGTERM) response = link_client.read - response.exit_status.should == 37 + expect(response.exit_status).to eq 37 end it "can kill everything ungracefully" do @@ -100,7 +100,7 @@ module Warden::Protocol # Test that no exit status is returned (because of SIGKILL) response = link_client.read - response.exit_status.should == 255 + expect(response.exit_status).to eq 255 end it "contains the container info" do @@ -110,7 +110,7 @@ module Warden::Protocol stop_client.stop(:handle => handle, :kill => true) response = link_client.read - response.info.should be_kind_of(InfoResponse) + expect(response.info).to be_kind_of(InfoResponse) end end @@ -162,7 +162,7 @@ module Warden::Protocol # Test that the container can still be referenced expect do response = client.run(:handle => handle, :script => "echo") - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 end.to_not raise_error # Wait for the original grace time to run out @@ -172,9 +172,9 @@ module Warden::Protocol # container and canceled the original grace time expect do response = client.run(:handle => handle, :script => "echo") - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 end.to_not raise_error end end end -end \ No newline at end of file +end diff --git a/warden/spec/support/examples/running_commands.rb b/warden/spec/support/examples/running_commands.rb index c6f95197..612c90eb 100644 --- a/warden/spec/support/examples/running_commands.rb +++ b/warden/spec/support/examples/running_commands.rb @@ -10,16 +10,16 @@ module Warden::Protocol it "should redirect stdout output" do response = client.run(:handle => handle, :script => "echo hi") - response.exit_status.should == 0 - response.stdout.should == "hi\n" - response.stderr.should == "" + expect(response.exit_status).to eq 0 + expect(response.stdout).to eq "hi\n" + expect(response.stderr).to eq "" end it "should redirect stderr output" do response = client.run(:handle => handle, :script => "echo hi 1>&2") - response.exit_status.should == 0 - response.stdout.should == "" - response.stderr.should == "hi\n" + expect(response.exit_status).to eq 0 + expect(response.stdout).to eq "" + expect(response.stderr).to eq "hi\n" end context "when log_tag is given" do @@ -56,7 +56,7 @@ def received_messages(num) em(timeout: 5) do request = Warden::Protocol::RunRequest.new request.handle = handle - request.script = "echo hi out; echo hi err 1>&2" + request.script = "echo hi out; echo hi err 1>&2; sleep 1" request.log_tag = "some_log_tag" client.call(request) EM.stop @@ -72,7 +72,7 @@ def received_messages(num) em(timeout: 5) do request = Warden::Protocol::SpawnRequest.new request.handle = handle - request.script = "echo hi out; echo hi err 1>&2" + request.script = "echo hi out; echo hi err 1>&2; sleep 1" request.log_tag = "some_log_tag" client.call(request) EM.stop @@ -87,7 +87,7 @@ def received_messages(num) it "should propagate exit status" do response = client.run(:handle => handle, :script => "exit 123") - response.exit_status.should == 123 + expect(response.exit_status).to eq 123 end context "when the container is destroyed" do @@ -104,7 +104,7 @@ def received_messages(num) # The command should not have exited cleanly response = client.read - response.exit_status.should_not == 0 + expect(response.exit_status).to_not eq 0 end it "includes container info" do @@ -112,7 +112,7 @@ def received_messages(num) other_client.destroy(:handle => handle) response = client.read - response.info.should be_kind_of(InfoResponse) + expect(response.info).to be_kind_of(InfoResponse) end end @@ -129,7 +129,7 @@ def received_messages(num) sleep 0.0 response = client.link(:handle => handle, :job_id => job_id) - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 end it "should link a finished job" do @@ -138,12 +138,12 @@ def received_messages(num) sleep 0.1 response = client.link(:handle => handle, :job_id => job_id) - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 end it "should return an error after a job has already been linked" do job_id = client.spawn(:handle => handle, :script => "sleep 0.0").job_id - client.link(:handle => handle, :job_id => job_id).should_not be_nil + expect(client.link(:handle => handle, :job_id => job_id)).to_not be_nil expect do client.link(:handle => handle, :job_id => job_id) @@ -173,14 +173,14 @@ def received_messages(num) r1 = c1.read r2 = c2.read - r1.should == r2 + expect(r1).to eq r2 end it "should work when the connection that spawned the job disconnects" do c1.disconnect response = c2.link(:handle => handle, :job_id => job_id) - response.exit_status.should == 0 + expect(response.exit_status).to eq 0 end end @@ -193,12 +193,12 @@ def received_messages(num) script = "( head -c #{1024 * 200} /dev/urandom; sleep 1 ) 1>&#{fd}" response = client.run(:handle => handle, :script => script, :discard_output => discard_output) - response.exit_status.should == 255 - response.send(io).size.should > 1024 * 100 - response.send(io).size.should <= 1024 * 100 + 1024 * 64 + expect(response.exit_status).to eq 255 + expect(response.send(io).size).to be > 1024 * 100 + expect(response.send(io).size).to be <= 1024 * 100 + 1024 * 64 # Test that iomux-spawn was killed - `ps ax | grep iomux-spawn | grep #{handle} | grep -v grep`.should == "" + expect(`ps ax | grep iomux-spawn | grep #{handle} | grep -v grep`).to eq "" end end end @@ -211,8 +211,8 @@ def received_messages(num) script = "( head -c #{1024 * 200} /dev/urandom; sleep 1 ) 1>&#{fd}" response = client.run(:handle => handle, :script => script, :discard_output => discard_output) - response.exit_status.should == 0 - response.send(io).size.should == 0 + expect(response.exit_status).to eq 0 + expect(response.send(io).size).to eq 0 end end end @@ -236,16 +236,16 @@ def stream(client, job_id) job_id = client.spawn(:handle => handle, :script => "printf A; sleep 0.1; printf B;").job_id r = stream(client, job_id) - r.select { |e| e.name == "stdout" }.collect(&:data).join.should == "AB" - r.select { |e| e.name == "stderr" }.collect(&:data).join.should == "" - r.last.exit_status.should == 0 + expect(r.select { |e| e.name == "stdout" }.collect(&:data).join).to eq "AB" + expect(r.select { |e| e.name == "stderr" }.collect(&:data).join).to eq "" + expect(r.last.exit_status).to eq 0 end it "includes container info" do job_id = client.spawn(:handle => handle, :script => "printf A; sleep 0.1; printf B;").job_id r = stream(client, job_id) - r.last.info.should be_kind_of(InfoResponse) + expect(r.last.info).to be_kind_of(InfoResponse) end it "should stream a finished job" do @@ -254,16 +254,16 @@ def stream(client, job_id) sleep 0.1 r = stream(client, job_id) - r.select { |e| e.name == "stdout" }.collect(&:data).join.should == "AB" - r.select { |e| e.name == "stderr" }.collect(&:data).join.should == "" - r.last.exit_status.should == 0 + expect(r.select { |e| e.name == "stdout" }.collect(&:data).join).to eq "AB" + expect(r.select { |e| e.name == "stderr" }.collect(&:data).join).to eq "" + expect(r.last.exit_status).to eq 0 end it "should return an error after a job has already been streamed" do job_id = client.spawn(:handle => handle, :script => "sleep 0.0").job_id r = stream(client, job_id) - r.should_not be_empty + expect(r).to_not be_empty expect do stream(client, job_id) @@ -283,9 +283,9 @@ def stream(client, job_id) # Attempt to stream the job again; the server should have left it in tact r = stream(client, job_id) - r.select { |e| e.name == "stdout" }.collect(&:data).join.should == "1\n2\n" - r.select { |e| e.name == "stderr" }.collect(&:data).join.should == "" - r.last.exit_status.should == 0 + expect(r.select { |e| e.name == "stdout" }.collect(&:data).join).to eq "1\n2\n" + expect(r.select { |e| e.name == "stderr" }.collect(&:data).join).to eq "" + expect(r.last.exit_status).to eq 0 end describe "on different connections" do @@ -316,14 +316,14 @@ def stream(client, job_id) t[:result].each { |r| r.info = nil } end - r[0].should == r[1] + expect(r[0]).to eq r[1] end it "should work when the connection that spawned the job disconnects" do c1.disconnect r = stream(c2, job_id) - r.should_not be_empty + expect(r).to_not be_empty end end @@ -334,12 +334,12 @@ def stream(client, job_id) job_id = client.spawn(:handle => handle, :script => script).job_id responses = stream(client, job_id) - responses.last.exit_status.should == 255 - responses.map(&:data).join.size.should > 1024 * 100 - responses.map(&:data).join.size.should <= 1024 * 100 + 1024 * 64 + expect(responses.last.exit_status).to eq 255 + expect(responses.map(&:data).join.size).to be > 1024 * 100 + expect(responses.map(&:data).join.size).to be <= 1024 * 100 + 1024 * 64 # Test that iomux-spawn was killed - `ps ax | grep iomux-spawn | grep #{handle} | grep -v grep`.should == "" + expect(`ps ax | grep iomux-spawn | grep #{handle} | grep -v grep`).to eq "" end end end diff --git a/warden/spec/support/examples/snapshotting.rb b/warden/spec/support/examples/snapshotting.rb index a994d46a..ed8ef92b 100644 --- a/warden/spec/support/examples/snapshotting.rb +++ b/warden/spec/support/examples/snapshotting.rb @@ -2,22 +2,22 @@ it "should snapshot a container after creation" do handle = client.create.handle snapshot_path = File.join(container_depot_path, handle, "snapshot.json") - File.exist?(snapshot_path).should be_true + expect(File.exist?(snapshot_path)).to be true snapshot = Yajl::Parser.parse(File.read(snapshot_path)) - snapshot["state"].should == "active" + expect(snapshot["state"]).to eq "active" end it "should snapshot a container after it is stopped" do handle = client.create.handle snapshot_path = File.join(container_depot_path, handle, "snapshot.json") - File.exist?(snapshot_path).should be_true + expect(File.exist?(snapshot_path)).to be true snapshot = Yajl::Parser.parse(File.read(snapshot_path)) - snapshot["state"].should == "active" + expect(snapshot["state"]).to eq "active" client.stop(:handle => handle) - File.exist?(snapshot_path).should be_true + expect(File.exist?(snapshot_path)).to be true snapshot = Yajl::Parser.parse(File.read(snapshot_path)) - snapshot["state"].should == "stopped" + expect(snapshot["state"]).to eq "stopped" end it "should snapshot a container when a spawned process exits" do @@ -26,9 +26,9 @@ client.spawn(:handle => handle, :script => "echo abc") snapshot_path = File.join(container_depot_path, handle, "snapshot.json") - File.exist?(snapshot_path).should be_true + expect(File.exist?(snapshot_path)).to be true snapshot = Yajl::Parser.parse(File.read(snapshot_path)) - snapshot["jobs"].keys.size.should == 1 + expect(snapshot["jobs"].keys.size).to eq 1 end it "should create empty snapshots for alive processes" do @@ -37,12 +37,12 @@ client.spawn(:handle => handle, :script => "sleep 2; echo abc") snapshot_path = File.join(container_depot_path, handle, "snapshot.json") - File.exist?(snapshot_path).should be_true + expect(File.exist?(snapshot_path)).to be true snapshot = Yajl::Parser.parse(File.read(snapshot_path)) - snapshot["jobs"].keys.size.should == 1 + expect(snapshot["jobs"].keys.size).to eq 1 job_snapshot = snapshot["jobs"].values.first - job_snapshot.should be_an_instance_of Hash + expect(job_snapshot).to be_an_instance_of Hash end end @@ -52,9 +52,9 @@ client.net_in(:handle => handle) snapshot_path = File.join(container_depot_path, handle, "snapshot.json") - File.exist?(snapshot_path).should be_true + expect(File.exist?(snapshot_path)).to be true snapshot = Yajl::Parser.parse(File.read(snapshot_path)) - snapshot["resources"]["ports"].size.should == 1 + expect(snapshot["resources"]["ports"].size).to eq 1 end it "should create empty snapshot for alive processes after net_in request" do @@ -63,12 +63,12 @@ client.net_in(:handle => handle) snapshot_path = File.join(container_depot_path, handle, "snapshot.json") - File.exist?(snapshot_path).should be_true + expect(File.exist?(snapshot_path)).to be true snapshot = Yajl::Parser.parse(File.read(snapshot_path)) - snapshot["jobs"].keys.size.should == 1 + expect(snapshot["jobs"].keys.size).to eq 1 job_snapshot = snapshot["jobs"].values.first - job_snapshot.should be_an_instance_of Hash + expect(job_snapshot).to be_an_instance_of Hash end end @@ -78,10 +78,10 @@ client.net_out(:handle => handle, :network => "1.2.3.0/32", :port => 8765, :protocol => Warden::Protocol::NetOutRequest::Protocol::TCP) snapshot_path = File.join(container_depot_path, handle, "snapshot.json") - File.exist?(snapshot_path).should be_true + expect(File.exist?(snapshot_path)).to be true snapshot = Yajl::Parser.parse(File.read(snapshot_path)) - snapshot["resources"]["net_out"].size.should == 1 - snapshot["resources"]["net_out"].first.should eq ["1.2.3.0/32", "8765", "tcp", nil, nil] + expect(snapshot["resources"]["net_out"].size).to eq 1 + expect(snapshot["resources"]["net_out"].first).to eq ["1.2.3.0/32", "8765", "tcp", nil, nil] end -end \ No newline at end of file +end diff --git a/warden/spec/support/helpers/drain.rb b/warden/spec/support/helpers/drain.rb index ea294504..f7cd9177 100644 --- a/warden/spec/support/helpers/drain.rb +++ b/warden/spec/support/helpers/drain.rb @@ -28,7 +28,7 @@ def read_streams(cli, handle, job_id) def get_uid(client, handle) run_resp = client.run(:handle => handle, :script => "id -u") - run_resp.exit_status.should == 0 + expect(run_resp.exit_status).to eq 0 Integer(run_resp.stdout.chomp) end @@ -37,16 +37,19 @@ def check_request_broken(&blk) t = Thread.new do expect do - blk.call - end.to raise_error + blk.call(handle) + end.to raise_error do |error| + expect(error).to be_a(EOFError) | be_a(Errno::EPIPE) + end end # Force the request before the drain t.run if t.alive? + sleep 1 drain t.join end end -end \ No newline at end of file +end