diff options
author | Bryan McLellan <btm@opscode.com> | 2012-08-30 12:49:32 -0700 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2012-08-30 12:49:39 -0700 |
commit | 469b4e71504f56566468d35fe4922a888fc98145 (patch) | |
tree | 9ae266ceda8d39fbe2e3a83c65b58926f3247d84 | |
parent | cf00871d517b0b8ad85537e448559a98fc1501fa (diff) | |
download | chef-469b4e71504f56566468d35fe4922a888fc98145.tar.gz |
CHEF-3380: add spec tests for redhat service provider
-rw-r--r-- | chef/spec/unit/provider/service/redhat_spec.rb | 33 |
1 files 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 |