diff options
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/provider/service/solaris_smf_service_spec.rb | 38 | ||||
-rw-r--r-- | spec/unit/resource/service_spec.rb | 22 |
2 files changed, 58 insertions, 2 deletions
diff --git a/spec/unit/provider/service/solaris_smf_service_spec.rb b/spec/unit/provider/service/solaris_smf_service_spec.rb index c6835bed64..584176b944 100644 --- a/spec/unit/provider/service/solaris_smf_service_spec.rb +++ b/spec/unit/provider/service/solaris_smf_service_spec.rb @@ -198,6 +198,33 @@ describe Chef::Provider::Service::Solaris do end end + describe "when enabling the service recursively" do + before(:each) do + @provider.current_resource = @current_resource + end + + it "should call svcadm enable -s -r chef" do + @new_resource.options("-r") + expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status) + expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name) + expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", "-r", @current_resource.service_name).and_return(@success) + @provider.load_current_resource + expect(@provider.enable_service).to be_truthy + expect(@current_resource.enabled).to be_truthy + end + + it "should call svcadm enable -s -r -t chef when passed an array of options" do + @new_resource.options(["-r", "-t"]) + expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@enabled_svc_status) + expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm", "clear", @current_resource.service_name) + expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "enable", "-s", "-r", "-t", @current_resource.service_name).and_return(@success) + @provider.load_current_resource + expect(@provider.enable_service).to be_truthy + expect(@current_resource.enabled).to be_truthy + end + + end + describe "when disabling the service" do before(:each) do @provider.current_resource = @current_resource @@ -215,7 +242,16 @@ describe Chef::Provider::Service::Solaris do expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@disabled_svc_status) expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "disable", "-s", "chef").and_return(@success) @provider.load_current_resource - expect(@provider.stop_service).to be_truthy + expect(@provider.disable_service).to be_truthy + expect(@current_resource.enabled).to be_falsey + end + + it "should call svcadm disable chef with options" do + @new_resource.options("-t") + expect(@provider).to receive(:shell_out!).with("/bin/svcs", "-l", "chef", { :returns => [0, 1] }).and_return(@disabled_svc_status) + expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm", "disable", "-s", "-t", "chef").and_return(@success) + @provider.load_current_resource + expect(@provider.disable_service).to be_truthy expect(@current_resource.enabled).to be_falsey end diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb index 205282b99f..67a4635983 100644 --- a/spec/unit/resource/service_spec.rb +++ b/spec/unit/resource/service_spec.rb @@ -124,6 +124,27 @@ describe Chef::Resource::Service do end.to raise_error(ArgumentError) end + it "should accept an array for options" do + @resource.options ["-r", "-s"] + expect(@resource.options).to eql(["-r", "-s"]) + end + + it "should accept a string for options" do + @resource.options "-r" + expect(@resource.options).to eql(["-r"]) + end + + it "should accept a string with multiple flags for options" do + @resource.options "-r -s" + expect(@resource.options).to eql(["-r", "-s"]) + end + + it "should not accept a boolean for options" do + expect do + @resource.options true + end.to raise_error(ArgumentError) + end + %w{enabled running}.each do |attrib| it "should accept true for #{attrib}" do @resource.send(attrib, true) @@ -175,5 +196,4 @@ describe Chef::Resource::Service do expect(@resource.identity).to eq("superfriend") end end - end |