From 469b4e71504f56566468d35fe4922a888fc98145 Mon Sep 17 00:00:00 2001 From: Bryan McLellan Date: Thu, 30 Aug 2012 12:49:32 -0700 Subject: CHEF-3380: add spec tests for redhat service provider --- chef/spec/unit/provider/service/redhat_spec.rb | 33 +++++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/chef/spec/unit/provider/service/redhat_spec.rb b/chef/spec/unit/provider/service/redhat_spec.rb index 9cbad1144e..1ace22f829 100644 --- a/chef/spec/unit/provider/service/redhat_spec.rb +++ b/chef/spec/unit/provider/service/redhat_spec.rb @@ -74,15 +74,30 @@ describe "Chef::Provider::Service::Redhat" do @provider.define_resource_requirements lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) end - - it "should raise an error if the service does not exist" do - status = mock("Status", :exitstatus => 1, :stdout => "", :stderr => "chef: unrecognized service") - @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) - chkconfig = mock("Chkconfig", :existatus=> 1, :stdout => "", :stderr => "error reading information on service chef: No such file or directory") - @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) - @provider.load_current_resource - @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + + context "when the service does not exist" do + before do + status = mock("Status", :exitstatus => 1, :stdout => "", :stderr => "chef: unrecognized service") + @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) + chkconfig = mock("Chkconfig", :existatus=> 1, :stdout => "", :stderr => "error reading information on service chef: No such file or directory") + @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) + @provider.load_current_resource + @provider.define_resource_requirements + end + + [ "start", "enable" ].each do |action| + it "should raise an error when the action is #{action}" do + @provider.action = action + lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + end + end + + [ "stop", "disable" ].each do |action| + it "should not raise an error when the action is #{action}" do + @provider.action = action + lambda { @provider.process_resource_requirements }.should_not raise_error + end + end end it "should not raise an error if the service exists but is not added to any runlevels" do -- cgit v1.2.1