From a3fd8c19d9634588444c11928337ad6b52520572 Mon Sep 17 00:00:00 2001 From: Mike Dodge Date: Thu, 12 Mar 2015 00:01:08 -0700 Subject: First pass at fixing the unit tests --- spec/unit/provider/service/macosx_spec.rb | 85 ++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 30 deletions(-) (limited to 'spec/unit/provider/service/macosx_spec.rb') diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index fb751592df..d124d007dd 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -60,16 +60,14 @@ XML ["redis-server", "io.redis.redis-server"].each do |service_name| before do + allow(node).to receive(:[]).with("platform_version").and_return('10.10') + allow(Etc).to receive(:getlogin).and_return('igor') allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) - allow(provider).to receive(:shell_out!). - with("launchctl list", {:group => 1001, :user => 101}). - and_return(double("Status", :stdout => launchctl_stdout)) - allow(provider).to receive(:shell_out). - with(/launchctl list /, - {:group => nil, :user => nil}). + allow(provider).to receive(:shell_out_with_systems_locale). + with("su igor -c 'launchctl list #{service_name}'"). and_return(double("Status", :stdout => launchctl_stdout, :exitstatus => 0)) - allow(provider).to receive(:shell_out!). + allow(provider).to receive(:shell_out_with_systems_locale!). with(/plutil -convert xml1 -o/). and_return(double("Status", :stdout => plutil_stdout)) @@ -77,8 +75,8 @@ XML end context "#{service_name}" do - let(:new_resource) { Chef::Resource::Service.new(service_name) } - let!(:current_resource) { Chef::Resource::Service.new(service_name) } + let(:new_resource) { Chef::Resource::MacosxService.new(service_name) } + let!(:current_resource) { Chef::Resource::MacosxService.new(service_name) } describe "#load_current_resource" do @@ -120,10 +118,20 @@ XML context "when launchctl returns pid in service list" do let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } - 12761 - 0x100114220.old.machinit.thing - 7777 - io.redis.redis-server - - - com.lol.stopped-thing - SVC_LIST +{ + "LimitLoadToSessionType" = "System"; + "Label" = "io.redis.redis-server"; + "TimeOut" = 30; + "OnDemand" = false; + "LastExitStatus" = 0; + "PID" = 62803; + "Program" = "do_some.sh"; + "ProgramArguments" = ( + "path/to/do_something.sh"; + "-f"; + ); +}; +SVC_LIST before do provider.load_current_resource @@ -140,9 +148,19 @@ XML describe "running unsupported actions" do let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } -12761 - 0x100114220.old.machinit.thing -7777 - io.redis.redis-server -- - com.lol.stopped-thing +{ + "LimitLoadToSessionType" = "System"; + "Label" = "io.redis.redis-server"; + "TimeOut" = 30; + "OnDemand" = false; + "LastExitStatus" = 0; + "PID" = 62803; + "Program" = "do_some.sh"; + "ProgramArguments" = ( + "path/to/do_something.sh"; + "-f"; + ); +}; SVC_LIST before do @@ -154,10 +172,19 @@ SVC_LIST end context "when launchctl returns empty service pid" do let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } - 12761 - 0x100114220.old.machinit.thing - - - io.redis.redis-server - - - com.lol.stopped-thing - SVC_LIST +{ + "LimitLoadToSessionType" = "System"; + "Label" = "io.redis.redis-server"; + "TimeOut" = 30; + "OnDemand" = false; + "LastExitStatus" = 0; + "Program" = "do_some.sh"; + "ProgramArguments" = ( + "path/to/do_something.sh"; + "-f"; + ); +}; +SVC_LIST before do provider.load_current_resource @@ -232,15 +259,14 @@ SVC_LIST it "shows warning message if service is already running" do allow(current_resource).to receive(:running).and_return(true) - expect(Chef::Log).to receive(:debug).with("service[#{service_name}] already running, not starting") + expect(Chef::Log).to receive(:debug).with("macosx_service[#{service_name}] already running, not starting") provider.start_service end it "starts service via launchctl if service found" do - expect(provider).to receive(:shell_out_with_systems_locale!). - with("launchctl load -w '/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'", - :group => 1001, :user => 101). + expect(provider).to receive(:shell_out_with_systems_locale). + with("su igor -c 'launchctl load -w -S Aqua /Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'"). and_return(0) provider.start_service @@ -264,15 +290,14 @@ SVC_LIST it "shows warning message if service is not running" do allow(current_resource).to receive(:running).and_return(false) - expect(Chef::Log).to receive(:debug).with("service[#{service_name}] not running, not stopping") + expect(Chef::Log).to receive(:debug).with("macosx_service[#{service_name}] not running, not stopping") provider.stop_service end it "stops the service via launchctl if service found" do - expect(provider).to receive(:shell_out_with_systems_locale!). - with("launchctl unload '/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'", - :group => 1001, :user => 101). + expect(provider).to receive(:shell_out_with_systems_locale). + with("su igor -c 'launchctl unload -w /Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'"). and_return(0) provider.stop_service @@ -296,8 +321,8 @@ SVC_LIST end it "stops and then starts service" do - expect(provider).to receive(:stop_service) - expect(provider).to receive(:start_service); + expect(provider).to receive(:unload_service) + expect(provider).to receive(:load_service); provider.restart_service end -- cgit v1.2.1 From fd0bfd4c60c64888ff6f9d0e82e365f091b82347 Mon Sep 17 00:00:00 2001 From: Mike Dodge Date: Thu, 12 Mar 2015 01:52:15 -0700 Subject: Updated tests to match new logic --- spec/unit/provider/service/macosx_spec.rb | 41 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'spec/unit/provider/service/macosx_spec.rb') diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index d124d007dd..830ac293c4 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -58,25 +58,30 @@ describe Chef::Provider::Service::Macosx do XML - ["redis-server", "io.redis.redis-server"].each do |service_name| + ["Daemon", "Agent"].each do |service_type| before do + @service_name = 'io.redis.redis-server' + @plist = '/Library/LaunchDaemons/io.redis.redis-server.plist' + if service_type.include?('Agent') + @plist = '/Library/LaunchAgents/io.redis.redis-server.plist' + end allow(node).to receive(:[]).with("platform_version").and_return('10.10') allow(Etc).to receive(:getlogin).and_return('igor') - allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) + allow(Dir).to receive(:glob).and_return([@plist], []) + @su_cmd = 'su igor -c' + cmd = "launchctl list #{@service_name}" allow(provider).to receive(:shell_out_with_systems_locale). - with("su igor -c 'launchctl list #{service_name}'"). + with(/(#{@su_cmd} '#{cmd}'|#{cmd})/). and_return(double("Status", :stdout => launchctl_stdout, :exitstatus => 0)) allow(provider).to receive(:shell_out_with_systems_locale!). with(/plutil -convert xml1 -o/). and_return(double("Status", :stdout => plutil_stdout)) - - allow(File).to receive(:stat).and_return(double("stat", :gid => 1001, :uid => 101)) end - context "#{service_name}" do - let(:new_resource) { Chef::Resource::MacosxService.new(service_name) } - let!(:current_resource) { Chef::Resource::MacosxService.new(service_name) } + context "#{@service_name}" do + let(:new_resource) { Chef::Resource::MacosxService.new(@service_name) } + let!(:current_resource) { Chef::Resource::MacosxService.new(@service_name) } describe "#load_current_resource" do @@ -164,7 +169,7 @@ SVC_LIST SVC_LIST before do - allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) + allow(Dir).to receive(:glob).and_return(["#{@plist}"], []) end it "should throw an exception when reload action is attempted" do expect {provider.run_action(:reload)}.to raise_error(Chef::Exceptions::UnsupportedAction) @@ -201,8 +206,7 @@ SVC_LIST context "when launchctl doesn't return service entry at all" do let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } - 12761 - 0x100114220.old.machinit.thing - - - com.lol.stopped-thing + Could not find service "io.redis.redis-server" in domain for system SVC_LIST it "sets service running state to false" do @@ -223,7 +227,7 @@ SVC_LIST context "and plist for service is available" do before do - allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) + allow(Dir).to receive(:glob).and_return(["#{@plist}"], []) provider.load_current_resource end @@ -234,7 +238,7 @@ SVC_LIST describe "and several plists match service name" do it "throws exception" do - allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist", + allow(Dir).to receive(:glob).and_return(["#{@plist}", "/Users/wtf/something.plist"]) provider.load_current_resource provider.define_resource_requirements @@ -259,14 +263,16 @@ SVC_LIST it "shows warning message if service is already running" do allow(current_resource).to receive(:running).and_return(true) - expect(Chef::Log).to receive(:debug).with("macosx_service[#{service_name}] already running, not starting") + expect(Chef::Log).to receive(:debug).with("macosx_service[#{@service_name}] already running, not starting") provider.start_service end it "starts service via launchctl if service found" do + session_type = @plist.include?('Agent') ? "-S Aqua " : '' + cmd = 'launchctl load -w ' + session_type + @plist expect(provider).to receive(:shell_out_with_systems_locale). - with("su igor -c 'launchctl load -w -S Aqua /Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'"). + with(/(#{@su_cmd} .#{cmd}.|#{cmd})/). and_return(0) provider.start_service @@ -290,14 +296,15 @@ SVC_LIST it "shows warning message if service is not running" do allow(current_resource).to receive(:running).and_return(false) - expect(Chef::Log).to receive(:debug).with("macosx_service[#{service_name}] not running, not stopping") + expect(Chef::Log).to receive(:debug).with("macosx_service[#{@service_name}] not running, not stopping") provider.stop_service end it "stops the service via launchctl if service found" do + cmd = "launchctl unload -w #{@plist}" expect(provider).to receive(:shell_out_with_systems_locale). - with("su igor -c 'launchctl unload -w /Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'"). + with(/(#{@su_cmd} .#{cmd}.|#{cmd})/). and_return(0) provider.stop_service -- cgit v1.2.1 From 0486e802d5eb966d4da058a367527ed556df711a Mon Sep 17 00:00:00 2001 From: Mike Dodge Date: Thu, 12 Mar 2015 18:33:44 -0700 Subject: added tests for 100% of use cases --- spec/unit/provider/service/macosx_spec.rb | 394 +++++++++++++++--------------- 1 file changed, 201 insertions(+), 193 deletions(-) (limited to 'spec/unit/provider/service/macosx_spec.rb') diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 830ac293c4..9607ac23ed 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -59,70 +59,77 @@ describe Chef::Provider::Service::Macosx do XML ["Daemon", "Agent"].each do |service_type| - before do - @service_name = 'io.redis.redis-server' - @plist = '/Library/LaunchDaemons/io.redis.redis-server.plist' - if service_type.include?('Agent') - @plist = '/Library/LaunchAgents/io.redis.redis-server.plist' - end - allow(node).to receive(:[]).with("platform_version").and_return('10.10') - allow(Etc).to receive(:getlogin).and_return('igor') - allow(Dir).to receive(:glob).and_return([@plist], []) - @su_cmd = 'su igor -c' - cmd = "launchctl list #{@service_name}" - allow(provider).to receive(:shell_out_with_systems_locale). - with(/(#{@su_cmd} '#{cmd}'|#{cmd})/). - and_return(double("Status", - :stdout => launchctl_stdout, :exitstatus => 0)) - allow(provider).to receive(:shell_out_with_systems_locale!). - with(/plutil -convert xml1 -o/). - and_return(double("Status", :stdout => plutil_stdout)) - end - - context "#{@service_name}" do - let(:new_resource) { Chef::Resource::MacosxService.new(@service_name) } - let!(:current_resource) { Chef::Resource::MacosxService.new(@service_name) } - - describe "#load_current_resource" do - - # CHEF-5223 "you can't glob for a file that hasn't been converged - # onto the node yet." - context "when the plist doesn't exist" do - - def run_resource_setup_for_action(action) - new_resource.action(action) - provider.action = action - provider.load_current_resource - provider.define_resource_requirements - provider.process_resource_requirements - end - - before do - allow(Dir).to receive(:glob).and_return([]) - allow(provider).to receive(:shell_out!). - with(/plutil -convert xml1 -o/). - and_raise(Mixlib::ShellOut::ShellCommandFailed) - end - - it "works for action :nothing" do - expect { run_resource_setup_for_action(:nothing) }.not_to raise_error - end - - it "works for action :start" do - expect { run_resource_setup_for_action(:start) }.not_to raise_error - end - - it "errors if action is :enable" do - expect { run_resource_setup_for_action(:enable) }.to raise_error(Chef::Exceptions::Service) - end - - it "errors if action is :disable" do - expect { run_resource_setup_for_action(:disable) }.to raise_error(Chef::Exceptions::Service) + ["redis-server", "io.redis.redis-server"].each do |service_name| + ["10.9", "10.10"].each do |platform_version| + let(:plist) {'/Library/LaunchDaemons/io.redis.redis-server.plist'} + let(:session) { StringIO.new } + if service_type == 'Agent' + let(:plist) {'/Library/LaunchAgents/io.redis.redis-server.plist'} + let(:session) {'-S Aqua '} + let(:su_cmd) {'su igor -c'} + if platform_version != "10.10" + let(:su_cmd) {'su -l igor -c'} end end + let(:service_label) {'io.redis.redis-server'} + before do + allow(Dir).to receive(:glob).and_return([plist], []) + allow(Etc).to receive(:getlogin).and_return('igor') + allow(node).to receive(:[]).with("platform_version").and_return(platform_version) + cmd = "launchctl list #{service_label}" + allow(provider).to receive(:shell_out_with_systems_locale). + with(/(#{su_cmd} '#{cmd}'|#{cmd})/). + and_return(double("Status", + :stdout => launchctl_stdout, :exitstatus => 0)) + allow(provider).to receive(:shell_out_with_systems_locale!). + with(/plutil -convert xml1 -o/). + and_return(double("Status", :stdout => plutil_stdout)) + end + + context "#{service_name} that is a #{service_type} running Osx #{platform_version}" do + let(:new_resource) { Chef::Resource::MacosxService.new(service_name) } + let!(:current_resource) { Chef::Resource::MacosxService.new(service_name) } + + describe "#load_current_resource" do + + # CHEF-5223 "you can't glob for a file that hasn't been converged + # onto the node yet." + context "when the plist doesn't exist" do + + def run_resource_setup_for_action(action) + new_resource.action(action) + provider.action = action + provider.load_current_resource + provider.define_resource_requirements + provider.process_resource_requirements + end + + before do + allow(Dir).to receive(:glob).and_return([]) + allow(provider).to receive(:shell_out!). + with(/plutil -convert xml1 -o/). + and_raise(Mixlib::ShellOut::ShellCommandFailed) + end + + it "works for action :nothing" do + expect { run_resource_setup_for_action(:nothing) }.not_to raise_error + end + + it "works for action :start" do + expect { run_resource_setup_for_action(:start) }.not_to raise_error + end + + it "errors if action is :enable" do + expect { run_resource_setup_for_action(:enable) }.to raise_error(Chef::Exceptions::Service) + end + + it "errors if action is :disable" do + expect { run_resource_setup_for_action(:disable) }.to raise_error(Chef::Exceptions::Service) + end + end - context "when launchctl returns pid in service list" do - let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } + context "when launchctl returns pid in service list" do + let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } { "LimitLoadToSessionType" = "System"; "Label" = "io.redis.redis-server"; @@ -138,21 +145,21 @@ XML }; SVC_LIST - before do - provider.load_current_resource - end + before do + provider.load_current_resource + end - it "sets resource running state to true" do - expect(provider.current_resource.running).to be_truthy - end + it "sets resource running state to true" do + expect(provider.current_resource.running).to be_truthy + end - it "sets resouce enabled state to true" do - expect(provider.current_resource.enabled).to be_truthy - end - end + it "sets resouce enabled state to true" do + expect(provider.current_resource.enabled).to be_truthy + end + end - describe "running unsupported actions" do - let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } + describe "running unsupported actions" do + let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } { "LimitLoadToSessionType" = "System"; "Label" = "io.redis.redis-server"; @@ -168,15 +175,15 @@ SVC_LIST }; SVC_LIST - before do - allow(Dir).to receive(:glob).and_return(["#{@plist}"], []) - end - it "should throw an exception when reload action is attempted" do - expect {provider.run_action(:reload)}.to raise_error(Chef::Exceptions::UnsupportedAction) - end - end - context "when launchctl returns empty service pid" do - let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } + before do + allow(Dir).to receive(:glob).and_return(["#{plist}"], []) + end + it "should throw an exception when reload action is attempted" do + expect {provider.run_action(:reload)}.to raise_error(Chef::Exceptions::UnsupportedAction) + end + end + context "when launchctl returns empty service pid" do + let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } { "LimitLoadToSessionType" = "System"; "Label" = "io.redis.redis-server"; @@ -191,147 +198,148 @@ SVC_LIST }; SVC_LIST - before do - provider.load_current_resource - end - - it "sets resource running state to false" do - expect(provider.current_resource.running).to be_falsey - end - - it "sets resouce enabled state to true" do - expect(provider.current_resource.enabled).to be_truthy - end - end - - context "when launchctl doesn't return service entry at all" do - let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } - Could not find service "io.redis.redis-server" in domain for system - SVC_LIST + before do + provider.load_current_resource + end - it "sets service running state to false" do - provider.load_current_resource - expect(provider.current_resource.running).to be_falsey - end + it "sets resource running state to false" do + expect(provider.current_resource.running).to be_falsey + end - context "and plist for service is not available" do - before do - allow(Dir).to receive(:glob).and_return([]) - provider.load_current_resource + it "sets resouce enabled state to true" do + expect(provider.current_resource.enabled).to be_truthy + end end - it "sets resouce enabled state to false" do - expect(provider.current_resource.enabled).to be_falsey + context "when launchctl doesn't return service entry at all" do + let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } +Could not find service "io.redis.redis-server" in domain for system +SVC_LIST + + it "sets service running state to false" do + provider.load_current_resource + expect(provider.current_resource.running).to be_falsey + end + + context "and plist for service is not available" do + before do + allow(Dir).to receive(:glob).and_return([]) + provider.load_current_resource + end + + it "sets resouce enabled state to false" do + expect(provider.current_resource.enabled).to be_falsey + end + end + + context "and plist for service is available" do + before do + allow(Dir).to receive(:glob).and_return(["#{plist}"], []) + provider.load_current_resource + end + + it "sets resouce enabled state to true" do + expect(provider.current_resource.enabled).to be_truthy + end + end + + describe "and several plists match service name" do + it "throws exception" do + allow(Dir).to receive(:glob).and_return(["#{plist}", + "/Users/wtf/something.plist"]) + provider.load_current_resource + provider.define_resource_requirements + expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) + end + end end end - - context "and plist for service is available" do + describe "#start_service" do before do - allow(Dir).to receive(:glob).and_return(["#{@plist}"], []) + allow(Chef::Resource::MacosxService).to receive(:new).and_return(current_resource) provider.load_current_resource + allow(current_resource).to receive(:running).and_return(false) end - it "sets resouce enabled state to true" do - expect(provider.current_resource.enabled).to be_truthy - end - end + it "calls the start command if one is specified and service is not running" do + allow(new_resource).to receive(:start_command).and_return("cowsay dirty") - describe "and several plists match service name" do - it "throws exception" do - allow(Dir).to receive(:glob).and_return(["#{@plist}", - "/Users/wtf/something.plist"]) - provider.load_current_resource - provider.define_resource_requirements - expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) + expect(provider).to receive(:shell_out_with_systems_locale!).with("cowsay dirty") + provider.start_service end - end - end - end - describe "#start_service" do - before do - allow(Chef::Resource::Service).to receive(:new).and_return(current_resource) - provider.load_current_resource - allow(current_resource).to receive(:running).and_return(false) - end - it "calls the start command if one is specified and service is not running" do - allow(new_resource).to receive(:start_command).and_return("cowsay dirty") + it "shows warning message if service is already running" do + allow(current_resource).to receive(:running).and_return(true) + expect(Chef::Log).to receive(:debug).with("macosx_service[#{service_name}] already running, not starting") - expect(provider).to receive(:shell_out_with_systems_locale!).with("cowsay dirty") - provider.start_service - end - - it "shows warning message if service is already running" do - allow(current_resource).to receive(:running).and_return(true) - expect(Chef::Log).to receive(:debug).with("macosx_service[#{@service_name}] already running, not starting") - - provider.start_service - end + provider.start_service + end - it "starts service via launchctl if service found" do - session_type = @plist.include?('Agent') ? "-S Aqua " : '' - cmd = 'launchctl load -w ' + session_type + @plist - expect(provider).to receive(:shell_out_with_systems_locale). - with(/(#{@su_cmd} .#{cmd}.|#{cmd})/). - and_return(0) + it "starts service via launchctl if service found" do + cmd = 'launchctl load -w ' + session + plist + expect(provider).to receive(:shell_out_with_systems_locale). + with(/(#{su_cmd} .#{cmd}.|#{cmd})/). + and_return(0) - provider.start_service - end - end + provider.start_service + end + end - describe "#stop_service" do - before do - allow(Chef::Resource::Service).to receive(:new).and_return(current_resource) + describe "#stop_service" do + before do + allow(Chef::Resource::MacosxService).to receive(:new).and_return(current_resource) - provider.load_current_resource - allow(current_resource).to receive(:running).and_return(true) - end + provider.load_current_resource + allow(current_resource).to receive(:running).and_return(true) + end - it "calls the stop command if one is specified and service is running" do - allow(new_resource).to receive(:stop_command).and_return("kill -9 123") + it "calls the stop command if one is specified and service is running" do + allow(new_resource).to receive(:stop_command).and_return("kill -9 123") - expect(provider).to receive(:shell_out_with_systems_locale!).with("kill -9 123") - provider.stop_service - end + expect(provider).to receive(:shell_out_with_systems_locale!).with("kill -9 123") + provider.stop_service + end - it "shows warning message if service is not running" do - allow(current_resource).to receive(:running).and_return(false) - expect(Chef::Log).to receive(:debug).with("macosx_service[#{@service_name}] not running, not stopping") + it "shows warning message if service is not running" do + allow(current_resource).to receive(:running).and_return(false) + expect(Chef::Log).to receive(:debug).with("macosx_service[#{service_name}] not running, not stopping") - provider.stop_service - end + provider.stop_service + end - it "stops the service via launchctl if service found" do - cmd = "launchctl unload -w #{@plist}" - expect(provider).to receive(:shell_out_with_systems_locale). - with(/(#{@su_cmd} .#{cmd}.|#{cmd})/). - and_return(0) + it "stops the service via launchctl if service found" do + cmd = 'launchctl unload -w '+ plist + expect(provider).to receive(:shell_out_with_systems_locale). + with(/(#{su_cmd} .#{cmd}.|#{cmd})/). + and_return(0) - provider.stop_service - end - end + provider.stop_service + end + end - describe "#restart_service" do - before do - allow(Chef::Resource::Service).to receive(:new).and_return(current_resource) + describe "#restart_service" do + before do + allow(Chef::Resource::Service).to receive(:new).and_return(current_resource) - provider.load_current_resource - allow(current_resource).to receive(:running).and_return(true) - allow(provider).to receive(:sleep) - end + provider.load_current_resource + allow(current_resource).to receive(:running).and_return(true) + allow(provider).to receive(:sleep) + end - it "issues a command if given" do - allow(new_resource).to receive(:restart_command).and_return("reload that thing") + it "issues a command if given" do + allow(new_resource).to receive(:restart_command).and_return("reload that thing") - expect(provider).to receive(:shell_out_with_systems_locale!).with("reload that thing") - provider.restart_service - end + expect(provider).to receive(:shell_out_with_systems_locale!).with("reload that thing") + provider.restart_service + end - it "stops and then starts service" do - expect(provider).to receive(:unload_service) - expect(provider).to receive(:load_service); + it "stops and then starts service" do + expect(provider).to receive(:unload_service) + expect(provider).to receive(:load_service); - provider.restart_service + provider.restart_service + end + end end end end -- cgit v1.2.1 From 5b8fcf1e8285643e797090de505f33d5aab2a89f Mon Sep 17 00:00:00 2001 From: Mike Dodge Date: Wed, 25 Mar 2015 00:10:04 -0700 Subject: addressed each of the comments --- spec/unit/provider/service/macosx_spec.rb | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'spec/unit/provider/service/macosx_spec.rb') diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 9607ac23ed..4337ee2cee 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -159,22 +159,6 @@ SVC_LIST end describe "running unsupported actions" do - let(:launchctl_stdout) { StringIO.new <<-SVC_LIST } -{ - "LimitLoadToSessionType" = "System"; - "Label" = "io.redis.redis-server"; - "TimeOut" = 30; - "OnDemand" = false; - "LastExitStatus" = 0; - "PID" = 62803; - "Program" = "do_some.sh"; - "ProgramArguments" = ( - "path/to/do_something.sh"; - "-f"; - ); -}; -SVC_LIST - before do allow(Dir).to receive(:glob).and_return(["#{plist}"], []) end -- cgit v1.2.1 From 0d1bc71edebcf4b7e11b5640c9331bc13030bf91 Mon Sep 17 00:00:00 2001 From: Mike Dodge Date: Thu, 26 Mar 2015 15:09:19 -0700 Subject: added requsted chagnes --- spec/unit/provider/service/macosx_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/unit/provider/service/macosx_spec.rb') diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 4337ee2cee..76301a8129 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -161,6 +161,7 @@ SVC_LIST describe "running unsupported actions" do before do allow(Dir).to receive(:glob).and_return(["#{plist}"], []) + allow(File).to receive(:exists?).and_return([true], []) end it "should throw an exception when reload action is attempted" do expect {provider.run_action(:reload)}.to raise_error(Chef::Exceptions::UnsupportedAction) -- cgit v1.2.1 From 455aaf2b879f341eea406b2004ff9524544da96e Mon Sep 17 00:00:00 2001 From: Mike Dodge Date: Wed, 1 Apr 2015 13:35:03 -0700 Subject: adding assert for plist --- spec/unit/provider/service/macosx_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/unit/provider/service/macosx_spec.rb') diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 76301a8129..42d45f09e0 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -81,6 +81,7 @@ XML with(/(#{su_cmd} '#{cmd}'|#{cmd})/). and_return(double("Status", :stdout => launchctl_stdout, :exitstatus => 0)) + allow(File).to receive(:exists?).and_return([true], []) allow(provider).to receive(:shell_out_with_systems_locale!). with(/plutil -convert xml1 -o/). and_return(double("Status", :stdout => plutil_stdout)) @@ -106,6 +107,7 @@ XML before do allow(Dir).to receive(:glob).and_return([]) + allow(File).to receive(:exists?).and_return([true], []) allow(provider).to receive(:shell_out!). with(/plutil -convert xml1 -o/). and_raise(Mixlib::ShellOut::ShellCommandFailed) -- cgit v1.2.1