summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2014-06-24 23:20:17 -0700
committerClaire McQuin <claire@getchef.com>2014-06-30 08:31:38 -0700
commitfc8a6e870c5d8c56099b299335a28b4eab3eaa0b (patch)
tree49fc3384e759fc56fc36267fc51bfea03a1dd19a
parentb09a5eb05075b30efdc77a40e041b1fa8be0288a (diff)
downloadchef-fc8a6e870c5d8c56099b299335a28b4eab3eaa0b.tar.gz
Update spec for shell_out.
-rw-r--r--spec/unit/provider/service/systemd_service_spec.rb71
1 files changed, 44 insertions, 27 deletions
diff --git a/spec/unit/provider/service/systemd_service_spec.rb b/spec/unit/provider/service/systemd_service_spec.rb
index f631bfc31d..2aa7b539f2 100644
--- a/spec/unit/provider/service/systemd_service_spec.rb
+++ b/spec/unit/provider/service/systemd_service_spec.rb
@@ -25,6 +25,11 @@ describe Chef::Provider::Service::Systemd do
@run_context = Chef::RunContext.new(@node, {}, @events)
@new_resource = Chef::Resource::Service.new('rsyslog.service')
@provider = Chef::Provider::Service::Systemd.new(@new_resource, @run_context)
+
+ @shell_out_success = double('shell_out_with_systems_locale',
+ :exitstatus => 0, :error? => false)
+ @shell_out_failure = double('shell_out_with_systems_locale',
+ :exitstatus => 1, :error? => true)
end
describe "load_current_resource" do
@@ -69,25 +74,25 @@ describe Chef::Provider::Service::Systemd do
end
it "should run the services status command if one has been specified" do
- @provider.stub(:run_command_with_systems_locale).with({:command => "/bin/chefhasmonkeypants status"}).and_return(0)
+ @provider.stub(:shell_out_with_systems_locale).and_return(@shell_out_success)
@current_resource.should_receive(:running).with(true)
@provider.load_current_resource
end
it "should run the services status command if one has been specified and properly set status check state" do
- @provider.stub(:run_command_with_systems_locale).with({:command => "/bin/chefhasmonkeypants status"}).and_return(0)
+ @provider.stub(:shell_out_with_systems_locale).with("/bin/chefhasmonkeypants status").and_return(@shell_out_success)
@provider.load_current_resource
@provider.instance_variable_get("@status_check_success").should be_true
end
- it "should set running to false if it catches a Chef::Exceptions::Exec when using a status command" do
- @provider.stub(:run_command_with_systems_locale).and_raise(Chef::Exceptions::Exec)
+ it "should set running to false if a status command fails" do
+ @provider.stub(:shell_out_with_systems_locale).and_return(@shell_out_failure)
@current_resource.should_receive(:running).with(false)
@provider.load_current_resource
end
- it "should update state to indicate status check failed when an exception is thrown using a status command" do
- @provider.stub(:run_command_with_systems_locale).and_raise(Chef::Exceptions::Exec)
+ it "should update state to indicate status check failed when a status command fails" do
+ @provider.stub(:shell_out_with_systems_locale).and_return(@shell_out_failure)
@provider.load_current_resource
@provider.instance_variable_get("@status_check_success").should be_false
end
@@ -129,13 +134,13 @@ describe Chef::Provider::Service::Systemd do
end
it "should call '/bin/systemctl start service_name' if no start command is specified" do
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl start #{@new_resource.service_name}"}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl start #{@new_resource.service_name}").and_return(@shell_out_success)
@provider.start_service
end
it "should not call '/bin/systemctl start service_name' if it is already running" do
@current_resource.stub(:running).and_return(true)
- @provider.should_not_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl start #{@new_resource.service_name}"})
+ @provider.should_not_receive(:shell_out_with_systems_locale).with("/bin/systemctl start #{@new_resource.service_name}")
@provider.start_service
end
@@ -148,21 +153,33 @@ describe Chef::Provider::Service::Systemd do
it "should call '/bin/systemctl restart service_name' if no restart command is specified" do
@current_resource.stub(:running).and_return(true)
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl restart #{@new_resource.service_name}"}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl restart #{@new_resource.service_name}").and_return(@shell_out_success)
@provider.restart_service
end
- it "should call the reload command if one is specified" do
- @current_resource.stub(:running).and_return(true)
- @new_resource.stub(:reload_command).and_return("/sbin/rsyslog reloadyousillysally")
- @provider.should_receive(:shell_out!).with("/sbin/rsyslog reloadyousillysally")
- @provider.reload_service
- end
+ describe "reload service" do
+ context "when a reload command is specified" do
+ it "should call the reload command" do
+ @current_resource.stub(:running).and_return(true)
+ @new_resource.stub(:reload_command).and_return("/sbin/rsyslog reloadyousillysally")
+ @provider.should_receive(:shell_out!).with("/sbin/rsyslog reloadyousillysally")
+ @provider.reload_service
+ end
+ end
- it "should call '/bin/systemctl reload service_name' if no reload command is specified" do
- @current_resource.stub(:running).and_return(true)
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl reload #{@new_resource.service_name}"}).and_return(0)
- @provider.reload_service
+ context "when a reload command is not specified" do
+ it "should call '/bin/systemctl reload service_name' if the service is running" do
+ @current_resource.stub(:running).and_return(true)
+ @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl reload #{@new_resource.service_name}").and_return(@shell_out_success)
+ @provider.reload_service
+ end
+
+ it "should start the service if the service is not running" do
+ @current_resource.stub(:running).and_return(false)
+ @provider.should_receive(:start_service).and_return(true)
+ @provider.reload_service
+ end
+ end
end
it "should call the stop command if one is specified" do
@@ -174,13 +191,13 @@ describe Chef::Provider::Service::Systemd do
it "should call '/bin/systemctl stop service_name' if no stop command is specified" do
@current_resource.stub(:running).and_return(true)
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl stop #{@new_resource.service_name}"}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl stop #{@new_resource.service_name}").and_return(@shell_out_success)
@provider.stop_service
end
it "should not call '/bin/systemctl stop service_name' if it is already stopped" do
@current_resource.stub(:running).and_return(false)
- @provider.should_not_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl stop #{@new_resource.service_name}"})
+ @provider.should_not_receive(:shell_out_with_systems_locale).with("/bin/systemctl stop #{@new_resource.service_name}")
@provider.stop_service
end
end
@@ -193,12 +210,12 @@ describe Chef::Provider::Service::Systemd do
end
it "should call '/bin/systemctl enable service_name' to enable the service" do
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl enable #{@new_resource.service_name}"}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl enable #{@new_resource.service_name}").and_return(@shell_out_success)
@provider.enable_service
end
it "should call '/bin/systemctl disable service_name' to disable the service" do
- @provider.should_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl disable #{@new_resource.service_name}"}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale).with("/bin/systemctl disable #{@new_resource.service_name}").and_return(@shell_out_success)
@provider.disable_service
end
end
@@ -210,12 +227,12 @@ describe Chef::Provider::Service::Systemd do
end
it "should return true if '/bin/systemctl is-active service_name' returns 0" do
- @provider.should_receive(:run_command_with_systems_locale).with({:command => '/bin/systemctl is-active rsyslog.service', :ignore_failure => true}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale).with('/bin/systemctl is-active rsyslog.service --quiet').and_return(@shell_out_success)
@provider.is_active?.should be_true
end
it "should return false if '/bin/systemctl is-active service_name' returns anything except 0" do
- @provider.should_receive(:run_command_with_systems_locale).with({:command => '/bin/systemctl is-active rsyslog.service', :ignore_failure => true}).and_return(1)
+ @provider.should_receive(:shell_out_with_systems_locale).with('/bin/systemctl is-active rsyslog.service --quiet').and_return(@shell_out_failure)
@provider.is_active?.should be_false
end
end
@@ -227,12 +244,12 @@ describe Chef::Provider::Service::Systemd do
end
it "should return true if '/bin/systemctl is-enabled service_name' returns 0" do
- @provider.should_receive(:run_command_with_systems_locale).with({:command => '/bin/systemctl is-enabled rsyslog.service', :ignore_failure => true}).and_return(0)
+ @provider.should_receive(:shell_out_with_systems_locale).with('/bin/systemctl is-enabled rsyslog.service --quiet').and_return(@shell_out_success)
@provider.is_enabled?.should be_true
end
it "should return false if '/bin/systemctl is-enabled service_name' returns anything except 0" do
- @provider.should_receive(:run_command_with_systems_locale).with({:command => '/bin/systemctl is-enabled rsyslog.service', :ignore_failure => true}).and_return(1)
+ @provider.should_receive(:shell_out_with_systems_locale).with('/bin/systemctl is-enabled rsyslog.service --quiet').and_return(@shell_out_failure)
@provider.is_enabled?.should be_false
end
end