summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-08-19 09:39:51 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2015-08-19 09:39:51 -0700
commita6f1e96882b872ad40c3c19c0b87b04abec3223b (patch)
tree037d97b99196c79f8ccfb3d0a2242e5f22174edf /spec
parent32bc91d5155fd71f757f08e19cf5cc79e6cd8bbf (diff)
downloadchef-a6f1e96882b872ad40c3c19c0b87b04abec3223b.tar.gz
spec and code fixes for run_levels
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/service/redhat_spec.rb70
1 files changed, 50 insertions, 20 deletions
diff --git a/spec/unit/provider/service/redhat_spec.rb b/spec/unit/provider/service/redhat_spec.rb
index 78be98f533..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,31 +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 => "")
- @current_resource.instance_variable_set(:@run_levels, [ 1, 2 ])
- @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status)
+ @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 => "")
- @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
- @provider.instance_variable_get("@service_missing").should be_false
- @provider.load_current_resource.should
- @current_resource.enabled.should be_true
+ 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 => "")
- @current_resource.instance_variable_set(:@run_levels, [ 2 ])
- @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status)
+ @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 => "")
- @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
- @provider.instance_variable_get("@service_missing").should be_false
- @provider.load_current_resource.should
- @current_resource.enabled.should be_true
+ 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
@@ -168,8 +182,24 @@ describe "Chef::Provider::Service::Redhat" do
end
it "should call chkconfig to add 'service_name' at specified run_levels" do
- @provider.instance_variable_set(:@run_levels, [ 1,2 ])
- @provider.should_receive(:shell_out!).with("/sbin/chkconfig --level 12 #{@new_resource.service_name} on")
+ 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
@@ -181,8 +211,8 @@ describe "Chef::Provider::Service::Redhat" do
end
it "should call chkconfig to del 'service_name' at specified run_levels" do
- @provider.instance_variable_set(:@run_levels, [ 1,2 ])
- @provider.should_receive(:shell_out!).with("/sbin/chkconfig --level 12 #{@new_resource.service_name} off")
+ 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