diff options
author | Bryan McLellan <btm@loftninjas.org> | 2014-08-12 16:38:43 -0400 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2014-08-12 16:55:21 -0400 |
commit | da3a410b1abeda93ff513f356d3c28a6d8d4aeb0 (patch) | |
tree | ca88453621694be63a2d35ea6f27f3ef59ca3371 | |
parent | eeb33043718d01ad2add0e4982cc557972d01ad2 (diff) | |
download | chef-da3a410b1abeda93ff513f356d3c28a6d8d4aeb0.tar.gz |
CHEF-5022: Add tests for #set_start_type and cleanup
-rw-r--r-- | lib/chef/resource/windows_service.rb | 3 | ||||
-rw-r--r-- | spec/unit/provider/service/windows_spec.rb | 18 |
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb index 1a70603f28..5ed8e76cbd 100644 --- a/lib/chef/resource/windows_service.rb +++ b/lib/chef/resource/windows_service.rb @@ -26,7 +26,7 @@ class Chef # to use action :configure_startup and attribute startup_type # provides :service, :on_platforms => ["windows"] - + identity_attr :service_name state_attrs :enabled, :running @@ -39,7 +39,6 @@ class Chef @startup_type = :automatic end - def startup_type(arg=nil) # Set-Service arguments are automatic and manual # Win32::Service returns 'auto start' or 'demand start' respectively, which the provider currently uses diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb index c51d07b20f..b16c59189b 100644 --- a/spec/unit/provider/service/windows_spec.rb +++ b/spec/unit/provider/service/windows_spec.rb @@ -289,7 +289,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do @provider.action_enable end end - + describe Chef::Provider::Service::Windows, "action_disable" do it "does nothing if the service is disabled" do Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( @@ -326,7 +326,6 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end end - # FIXME describe Chef::Provider::Service::Windows, "action_configure_startup" do { :automatic => "auto start", :manual => "demand start", :disabled => "disabled" }.each do |type,win32| it "sets the startup type to #{type} if it is something else" do @@ -344,7 +343,20 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end end end + describe Chef::Provider::Service::Windows, "set_start_type" do - #FIXME + allowed_types = { :automatic => Win32::Service::AUTO_START, + :manual => Win32::Service::DEMAND_START, + :disabled => Win32::Service::DISABLED } + allowed_types.each do |arg,win32_constant| + it "when called with #{arg} it calls Win32::Service#configure with #{win32_constant}" do + Win32::Service.should_receive(:configure).with(:service_name => @new_resource.service_name, :start_type => win32_constant) + @provider.send(:set_startup_type, arg) + end + end + + it "raises an exception when given an unknown start type" do + expect { @provider.send(:set_startup_type, :fire_truck) }.to raise_error(Chef::Exceptions::ConfigurationError) + end end end |