summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-08-19 14:55:35 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2015-08-19 14:55:35 -0700
commit214771ccc2564d3bf866fc5d0590cfa84d24df5f (patch)
tree9c6a73aea0d50d818b6689b892b35517ce92a477 /spec
parentb39409b4e3506c658b68f2b39a1005b7d5e36651 (diff)
parent7cf6d3ec000a5de116d31bb53ecd235392ea7050 (diff)
downloadchef-214771ccc2564d3bf866fc5d0590cfa84d24df5f.tar.gz
Merge pull request #3793 from chef/lcg/run_levels
Lcg/run levels
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/service/redhat_spec.rb72
1 files changed, 68 insertions, 4 deletions
diff --git a/spec/unit/provider/service/redhat_spec.rb b/spec/unit/provider/service/redhat_spec.rb
index 73cfec8a6f..1cb985714f 100644
--- a/spec/unit/provider/service/redhat_spec.rb
+++ b/spec/unit/provider/service/redhat_spec.rb
@@ -69,9 +69,9 @@ describe "Chef::Provider::Service::Redhat" do
expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status)
chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:on 6:off", :stderr => "")
expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
- expect(@provider.instance_variable_get("@service_missing")).to be_falsey
+ expect(@provider.service_missing).to be false
@provider.load_current_resource
- expect(@current_resource.enabled).to be_truthy
+ expect(@current_resource.enabled).to be true
end
it "sets the current enabled status to false if the regex does not match" do
@@ -79,9 +79,45 @@ describe "Chef::Provider::Service::Redhat" do
expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status)
chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:off 6:off", :stderr => "")
expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
- expect(@provider.instance_variable_get("@service_missing")).to be_falsey
+ expect(@provider.service_missing).to be false
expect(@provider.load_current_resource).to eql(@current_resource)
- expect(@current_resource.enabled).to be_falsey
+ expect(@current_resource.enabled).to be false
+ end
+
+ it "sets the current enabled status to true if the service is enabled at specified run levels" do
+ status = double("Status", :exitstatus => 0, :stdout => "" , :stderr => "")
+ @new_resource.run_levels([1, 2])
+ expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status)
+ chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:on 2:on 3:off 4:off 5:off 6:off", :stderr => "")
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
+ expect(@provider.service_missing).to be false
+ @provider.load_current_resource
+ expect(@current_resource.enabled).to be true
+ expect(@provider.current_run_levels).to eql([1, 2])
+ end
+
+ it "sets the current enabled status to false if the service is enabled at a run level it should not" do
+ status = double("Status", :exitstatus => 0, :stdout => "" , :stderr => "")
+ @new_resource.run_levels([1, 2])
+ expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status)
+ chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:on 2:on 3:on 4:off 5:off 6:off", :stderr => "")
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
+ expect(@provider.service_missing).to be false
+ @provider.load_current_resource
+ expect(@current_resource.enabled).to be false
+ expect(@provider.current_run_levels).to eql([1, 2, 3])
+ end
+
+ it "sets the current enabled status to false if the service is not enabled at specified run levels" do
+ status = double("Status", :exitstatus => 0, :stdout => "" , :stderr => "")
+ @new_resource.run_levels([ 2 ])
+ expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status)
+ chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:on 2:off 3:off 4:off 5:off 6:off", :stderr => "")
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
+ expect(@provider.service_missing).to be false
+ @provider.load_current_resource
+ expect(@current_resource.enabled).to be false
+ expect(@provider.current_run_levels).to eql([1])
end
end
@@ -144,6 +180,28 @@ describe "Chef::Provider::Service::Redhat" do
expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig #{@new_resource.service_name} on")
@provider.enable_service
end
+
+ it "should call chkconfig to add 'service_name' at specified run_levels" do
+ allow(@provider).to receive(:run_levels).and_return([1, 2])
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 12 #{@new_resource.service_name} on")
+ @provider.enable_service
+ end
+
+ it "should call chkconfig to add 'service_name' at specified run_levels when run_levels do not match" do
+ allow(@provider).to receive(:run_levels).and_return([1, 2])
+ allow(@provider).to receive(:current_run_levels).and_return([1, 3])
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 12 #{@new_resource.service_name} on")
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 3 #{@new_resource.service_name} off")
+ @provider.enable_service
+ end
+
+ it "should call chkconfig to add 'service_name' at specified run_levels if there is an extra run_level" do
+ allow(@provider).to receive(:run_levels).and_return([1, 2])
+ allow(@provider).to receive(:current_run_levels).and_return([1, 2, 3])
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 12 #{@new_resource.service_name} on")
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 3 #{@new_resource.service_name} off")
+ @provider.enable_service
+ end
end
describe "disable_service" do
@@ -151,6 +209,12 @@ describe "Chef::Provider::Service::Redhat" do
expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig #{@new_resource.service_name} off")
@provider.disable_service
end
+
+ it "should call chkconfig to del 'service_name' at specified run_levels" do
+ allow(@provider).to receive(:run_levels).and_return([1, 2])
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 12 #{@new_resource.service_name} off")
+ @provider.disable_service
+ end
end
end