diff options
author | Cameron Thomas <cameron@puppetlabs.com> | 2011-07-27 15:30:19 -0700 |
---|---|---|
committer | Jacob Helwig <jacob@puppetlabs.com> | 2011-08-19 13:52:59 -0700 |
commit | 4237cb1b12851d42504c9829fc61fe31cb84866c (patch) | |
tree | 16b1e23ec5e55a0ff029a2088fd369d6130e8fe3 /spec | |
parent | a32c8be4b32cfbc0588648e56e9194f3a75bbaa6 (diff) | |
download | puppet-4237cb1b12851d42504c9829fc61fe31cb84866c.tar.gz puppet-4237cb1b12851d42504c9829fc61fe31cb84866c.tar.xz puppet-4237cb1b12851d42504c9829fc61fe31cb84866c.zip |
(#8272) Add missing tests for Windows service provider methods.
Added missing spec tests for Windows service provider methods:
:stop, :enable, :disable, and :manual_start
Refactored to match Nick's previous work.
Reviewed By: Nick Lewis [nick@puppetlabs.com]
(cherry picked from commit d08ae7fd2180c95d1fcafa149128d25cc4680c6c)
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/unit/provider/service/windows_spec.rb | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb index 2012a184a..07e4f4d1a 100755 --- a/spec/unit/provider/service/windows_spec.rb +++ b/spec/unit/provider/service/windows_spec.rb @@ -33,7 +33,7 @@ describe Puppet::Type.type(:service).provider(:windows), :if => Puppet.features. it "should call out to the Win32::Service API to start the service" do @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_AUTO_START) - Win32::Service.expects(:start).with('snmptrap') + Win32::Service.expects(:start).with( @resource[:name] ) @resource.provider.start end @@ -41,13 +41,13 @@ describe Puppet::Type.type(:service).provider(:windows), :if => Puppet.features. it "should handle when Win32::Service.start raises a Win32::Service::Error" do @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_AUTO_START) - Win32::Service.expects(:start).with('snmptrap').raises( + Win32::Service.expects(:start).with( @resource[:name] ).raises( Win32::Service::Error.new("The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.") ) expect { @resource.provider.start }.to raise_error( Puppet::Error, - /Cannot start snmptrap, error was: The service cannot be started, either/ + /Cannot start .*, error was: The service cannot be started, either/ ) end @@ -80,8 +80,21 @@ describe Puppet::Type.type(:service).provider(:windows), :if => Puppet.features. end describe "#stop" do - it "should stop a running service" - it "should not try to stop an already stopped service" + it "should call out to the Win32::Service API to stop the service" do + Win32::Service.expects(:stop).with( @resource[:name] ) + @resource.provider.stop + end + + it "should handle when Win32::Service.stop raises a Win32::Service::Error" do + Win32::Service.expects(:stop).with( @resource[:name] ).raises( + Win32::Service::Error.new("should not try to stop an already stopped service.") + ) + + expect { @resource.provider.stop }.to raise_error( + Puppet::Error, + /Cannot stop .*, error was: should not try to stop an already stopped service/ + ) + end end describe "#status" do @@ -128,4 +141,26 @@ describe Puppet::Type.type(:service).provider(:windows), :if => Puppet.features. end end end + + describe "#enable" do + it "should set service start type to Service_Auto_Start when enabled" do + Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_AUTO_START).returns(Win32::Service) + @resource.provider.enable + end + end + + describe "#disable" do + it "should set service start type to Service_Disabled when disabled" do + Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DISABLED).returns(Win32::Service) + @resource.provider.disable + end + end + + describe "#manual_start" do + it "should set service start type to Service_Demand_Start (manual) when manual" do + Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DEMAND_START).returns(Win32::Service) + @resource.provider.manual_start + end + end + end |