summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-04-01 11:36:11 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2017-04-01 11:36:11 -0700
commite7330a21ab6427d0820799bc0f79db39faa7b866 (patch)
treeced3ff8ea4f8d70ecc98c042d45806e6a29e98d5
parent20b53061202d63d3acc29bffa317935a354abd5f (diff)
downloadchef-e7330a21ab6427d0820799bc0f79db39faa7b866.tar.gz
fix remaining specs for popen4 removal
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--spec/unit/provider/erl_call_spec.rb18
-rw-r--r--spec/unit/provider/service/debian_service_spec.rb30
-rw-r--r--spec/unit/provider/service/upstart_service_spec.rb37
-rw-r--r--spec/unit/provider/subversion_spec.rb4
-rw-r--r--spec/unit/provider/user/pw_spec.rb20
5 files changed, 34 insertions, 75 deletions
diff --git a/spec/unit/provider/erl_call_spec.rb b/spec/unit/provider/erl_call_spec.rb
index f1c229028a..b5d3ae8c07 100644
--- a/spec/unit/provider/erl_call_spec.rb
+++ b/spec/unit/provider/erl_call_spec.rb
@@ -31,11 +31,8 @@ describe Chef::Provider::ErlCall do
@provider = Chef::Provider::ErlCall.new(@new_resource, @run_context)
- allow(@provider).to receive(:popen4).and_return(@status)
- @stdin = StringIO.new
- @stdout = StringIO.new("{ok, woohoo}")
- @stderr = StringIO.new
- @pid = 2342999
+ @status = double("Status", stdout: "{ok, woohoo}", stderr: "")
+ allow(@provider).to receive(:shell_out!).and_return(@status)
end
it "should return a Chef::Provider::ErlCall object" do
@@ -56,12 +53,9 @@ describe Chef::Provider::ErlCall do
it "should write to stdin of the erl_call command" do
expected_cmd = "erl_call -e -s -sname chef@localhost -c nomnomnom"
- expect(@provider).to receive(:popen4).with(expected_cmd, :waitlast => true).and_return([@pid, @stdin, @stdout, @stderr])
- expect(Process).to receive(:wait).with(@pid)
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, input: @new_resource.code).and_return(@status)
@provider.action_run
-
- expect(@stdin.string).to eq("#{@new_resource.code}\n")
end
end
@@ -73,12 +67,10 @@ describe Chef::Provider::ErlCall do
end
it "should write to stdin of the erl_call command" do
- expect(@provider).to receive(:popen4).with("erl_call -e -name chef@localhost ", :waitlast => true).and_return([@pid, @stdin, @stdout, @stderr])
- expect(Process).to receive(:wait).with(@pid)
+ expected_cmd = "erl_call -e -name chef@localhost "
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, input: @new_resource.code).and_return(@status)
@provider.action_run
-
- expect(@stdin.string).to eq("#{@new_resource.code}\n")
end
end
diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb
index 799ed991a3..3a532ae216 100644
--- a/spec/unit/provider/service/debian_service_spec.rb
+++ b/spec/unit/provider/service/debian_service_spec.rb
@@ -59,11 +59,10 @@ describe Chef::Provider::Service::Debian do
/etc/rc6.d/K20chef
UPDATE_RC_D_SUCCESS
- @stdout = StringIO.new(result)
- @stderr = StringIO.new
- @status = double("Status", :exitstatus => 0, :stdout => @stdout)
+ @stdout = result
+ @stderr = ""
+ @status = double("Status", :exitstatus => 0, :stdout => @stdout, :stderr => @stderr)
allow(@provider).to receive(:shell_out!).and_return(@status)
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
end
it "says the service is enabled" do
@@ -80,13 +79,9 @@ describe Chef::Provider::Service::Debian do
context "when update-rc.d shows init isn't linked to rc*.d/" do
before do
allow(@provider).to receive(:assert_update_rcd_available)
- @status = double("Status", :exitstatus => 0)
- @stdout = StringIO.new(
- " Removing any system startup links for /etc/init.d/chef ...")
- @stderr = StringIO.new
- @status = double("Status", :exitstatus => 0, :stdout => @stdout)
+ @stdout = " Removing any system startup links for /etc/init.d/chef ..."
+ @status = double("Status", :exitstatus => 0, :stdout => @stdout, stderr: "")
allow(@provider).to receive(:shell_out!).and_return(@status)
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
end
it "says the service is disabled" do
@@ -103,7 +98,6 @@ describe Chef::Provider::Service::Debian do
context "when update-rc.d fails" do
before do
@status = double("Status", :exitstatus => -1)
- allow(@provider).to receive(:popen4).and_return(@status)
end
it "raises an error" do
@@ -198,11 +192,10 @@ insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop
before do
allow(@provider).to receive(:assert_update_rcd_available)
- @stdout = StringIO.new(expected_results["linked"]["stdout"])
- @stderr = StringIO.new(expected_results["linked"]["stderr"])
- @status = double("Status", :exitstatus => 0, :stdout => @stdout)
+ @stdout = expected_results["linked"]["stdout"]
+ @stderr = expected_results["linked"]["stderr"]
+ @status = double("Status", exitstatus: 0, stdout: @stdout, stderr: @stderr)
allow(@provider).to receive(:shell_out!).and_return(@status)
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
end
it "says the service is enabled" do
@@ -224,11 +217,10 @@ insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop
context "when update-rc.d shows init isn't linked to rc*.d/" do
before do
allow(@provider).to receive(:assert_update_rcd_available)
- @stdout = StringIO.new(expected_results["not linked"]["stdout"])
- @stderr = StringIO.new(expected_results["not linked"]["stderr"])
- @status = double("Status", :exitstatus => 0, :stdout => @stdout)
+ @stdout = expected_results["not linked"]["stdout"]
+ @stderr = expected_results["not linked"]["stderr"]
+ @status = double("Status", exitstatus: 0, stdout: @stdout, stderr: @stderr)
allow(@provider).to receive(:shell_out!).and_return(@status)
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
end
it "says the service is disabled" do
diff --git a/spec/unit/provider/service/upstart_service_spec.rb b/spec/unit/provider/service/upstart_service_spec.rb
index 0245dd038c..5c47259f52 100644
--- a/spec/unit/provider/service/upstart_service_spec.rb
+++ b/spec/unit/provider/service/upstart_service_spec.rb
@@ -71,12 +71,8 @@ describe Chef::Provider::Service::Upstart do
@current_resource = Chef::Resource::Service.new("rsyslog")
allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource)
- @status = double("Status", :exitstatus => 0)
- allow(@provider).to receive(:popen4).and_return(@status)
- @stdin = StringIO.new
- @stdout = StringIO.new
- @stderr = StringIO.new
- @pid = double("PID")
+ @status = double("Status", exitstatus: 0, stdout: "", stderr: "")
+ allow(@provider).to receive(:shell_out).and_return(@status)
allow(::File).to receive(:exists?).and_return(true)
allow(::File).to receive(:open).and_return(true)
@@ -100,28 +96,25 @@ describe Chef::Provider::Service::Upstart do
end
it "should run '/sbin/status rsyslog'" do
- expect(@provider).to receive(:popen4).with("/sbin/status rsyslog").and_return(@status)
+ expect(@provider).to receive(:shell_out).with("/sbin/status rsyslog").and_return(@status)
@provider.load_current_resource
end
describe "when the status command uses the new format" do
it "should set running to true if the goal state is 'start'" do
- @stdout = StringIO.new("rsyslog start/running")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ expect(@status).to receive(:stdout).and_return("rsyslog start/running")
@provider.load_current_resource
expect(@current_resource.running).to be_truthy
end
it "should set running to true if the goal state is 'start' but current state is not 'running'" do
- @stdout = StringIO.new("rsyslog start/starting")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ expect(@status).to receive(:stdout).and_return("rsyslog start/starting")
@provider.load_current_resource
expect(@current_resource.running).to be_truthy
end
it "should set running to false if the goal state is 'stop'" do
- @stdout = StringIO.new("rsyslog stop/waiting")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ expect(@status).to receive(:stdout).and_return("rsyslog stop/waiting")
@provider.load_current_resource
expect(@current_resource.running).to be_falsey
end
@@ -129,22 +122,19 @@ describe Chef::Provider::Service::Upstart do
describe "when the status command uses the new format with an instance" do
it "should set running to true if the goal state is 'start'" do
- @stdout = StringIO.new("rsyslog (test) start/running, process 100")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ expect(@status).to receive(:stdout).and_return("rsyslog (test) start/running, process 100")
@provider.load_current_resource
expect(@current_resource.running).to be_truthy
end
it "should set running to true if the goal state is 'start' but current state is not 'running'" do
- @stdout = StringIO.new("rsyslog (test) start/starting, process 100")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ expect(@status).to receive(:stdout).and_return("rsyslog (test) start/starting, process 100")
@provider.load_current_resource
expect(@current_resource.running).to be_truthy
end
it "should set running to false if the goal state is 'stop'" do
- @stdout = StringIO.new("rsyslog (test) stop/waiting, process 100")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ expect(@status).to receive(:stdout).and_return("rsyslog (test) stop/waiting, process 100")
@provider.load_current_resource
expect(@current_resource.running).to be_falsey
end
@@ -152,22 +142,19 @@ describe Chef::Provider::Service::Upstart do
describe "when the status command uses the old format" do
it "should set running to true if the goal state is 'start'" do
- @stdout = StringIO.new("rsyslog (start) running, process 32225")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ expect(@status).to receive(:stdout).and_return("rsyslog (start) running, process 32225")
@provider.load_current_resource
expect(@current_resource.running).to be_truthy
end
it "should set running to true if the goal state is 'start' but current state is not 'running'" do
- @stdout = StringIO.new("rsyslog (start) starting, process 32225")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ expect(@status).to receive(:stdout).and_return("rsyslog (start) starting, process 32225")
@provider.load_current_resource
expect(@current_resource.running).to be_truthy
end
it "should set running to false if the goal state is 'stop'" do
- @stdout = StringIO.new("rsyslog (stop) waiting")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ expect(@status).to receive(:stdout).and_return("rsyslog (stop) waiting")
@provider.load_current_resource
expect(@current_resource.running).to be_falsey
end
diff --git a/spec/unit/provider/subversion_spec.rb b/spec/unit/provider/subversion_spec.rb
index a4ab4ae42c..55d6dc5d24 100644
--- a/spec/unit/provider/subversion_spec.rb
+++ b/spec/unit/provider/subversion_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@kallistec.com>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -43,7 +43,7 @@ describe Chef::Provider::Subversion do
ENV.update(@original_env)
end
- it "converts resource attributes to options for run_command and popen4" do
+ it "converts resource attributes to options for shell_out" do
expect(@provider.run_options).to eq({})
@resource.user "deployninja"
expect(@provider.run_options).to eq({ :user => "deployninja" })
diff --git a/spec/unit/provider/user/pw_spec.rb b/spec/unit/provider/user/pw_spec.rb
index 3637ce0b95..913b0ae0ab 100644
--- a/spec/unit/provider/user/pw_spec.rb
+++ b/spec/unit/provider/user/pw_spec.rb
@@ -155,11 +155,7 @@ describe Chef::Provider::User::Pw do
describe "when modifying the password" do
before(:each) do
@status = double("Status", exitstatus: 0)
- allow(@provider).to receive(:popen4).and_return(@status)
- @pid = nil
- @stdin = nil
- @stdout = nil
- @stderr = nil
+ allow(@provider).to receive(:shell_out!).and_return(@status)
end
describe "and the new password has not been specified" do
@@ -206,24 +202,16 @@ describe Chef::Provider::User::Pw do
end
it "should run pw usermod with the username and the option -H 0" do
- expect(@provider).to receive(:popen4).with("pw usermod adam -H 0", waitlast: true).and_return(@status)
+ expect(@provider).to receive(:shell_out!).with("pw usermod adam -H 0", { :input => "abracadabra" }).and_return(@status)
@provider.modify_password
end
- it "should send the new password to the stdin of pw usermod" do
- @stdin = StringIO.new
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @provider.modify_password
- expect(@stdin.string).to eq("abracadabra\n")
- end
-
it "should raise an exception if pw usermod fails" do
- expect(@status).to receive(:exitstatus).and_return(1)
- expect { @provider.modify_password }.to raise_error(Chef::Exceptions::User)
+ expect(@provider).to receive(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed)
+ expect { @provider.modify_password }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
end
it "should not raise an exception if pw usermod succeeds" do
- expect(@status).to receive(:exitstatus).and_return(0)
expect { @provider.modify_password }.not_to raise_error
end
end