diff options
-rw-r--r-- | lib/chef/resource/windows_service.rb | 8 | ||||
-rw-r--r-- | spec/unit/resource/windows_service_spec.rb | 35 |
2 files changed, 33 insertions, 10 deletions
diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb index 14dd5e1520..33805ed482 100644 --- a/lib/chef/resource/windows_service.rb +++ b/lib/chef/resource/windows_service.rb @@ -47,17 +47,17 @@ class Chef validation_message: "The display_name can only be a maximum of 256 characters!", introduced: "14.0" - # https://github.com/djberg96/win32-service/blob/ffi/lib/win32/windows/constants.rb#L19-L29 + # https://github.com/chef/win32-service/blob/ffi/lib/win32/windows/constants.rb#L19-L29 property :desired_access, Integer, default: SERVICE_ALL_ACCESS - # https://github.com/djberg96/win32-service/blob/ffi/lib/win32/windows/constants.rb#L31-L41 + # https://github.com/chef/win32-service/blob/ffi/lib/win32/windows/constants.rb#L31-L41 property :service_type, Integer, default: SERVICE_WIN32_OWN_PROCESS # Valid options: # - :automatic # - :manual # - :disabled - # Reference: https://github.com/djberg96/win32-service/blob/ffi/lib/win32/windows/constants.rb#L49-L54 + # Reference: https://github.com/chef/win32-service/blob/ffi/lib/win32/windows/constants.rb#L49-L54 property :startup_type, [Symbol], equal_to: [:automatic, :manual, :disabled], default: :automatic, coerce: proc { |x| if x.is_a?(Integer) ALLOWED_START_TYPES.invert.fetch(x) do @@ -84,7 +84,7 @@ class Chef end } - # https://github.com/djberg96/win32-service/blob/ffi/lib/win32/windows/constants.rb#L43-L47 + # https://github.com/chef/win32-service/blob/ffi/lib/win32/windows/constants.rb#L43-L47 property :error_control, Integer, default: SERVICE_ERROR_NORMAL property :binary_path_name, String, diff --git a/spec/unit/resource/windows_service_spec.rb b/spec/unit/resource/windows_service_spec.rb index 114e903032..b44a86d04a 100644 --- a/spec/unit/resource/windows_service_spec.rb +++ b/spec/unit/resource/windows_service_spec.rb @@ -1,6 +1,6 @@ # # Author:: Bryan McLellan <btm@loftninjas.org> -# Copyright:: Copyright 2014-2016, Chef Software, Inc. +# Copyright:: Copyright 2014-2018, Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -48,9 +48,32 @@ describe Chef::Resource::WindowsService, "initialize" do expect { resource.action :unmask }.not_to raise_error end - it "supports setting startup_type" do - resource.startup_type(:manual) - expect(resource.startup_type).to eql(:manual) + [:automatic, :manual, :disabled].each do |type| + it "supports setting startup_type property to #{type.inspect}" do + resource.startup_type type + expect(resource.startup_type).to eql(type) + end + end + + { 2 => :automatic, 3 => :manual, 4 => :disabled }.each_pair do |k, v| + it "it coerces startup_type property #{k} to #{v.inspect}" do + resource.startup_type k + expect(resource.startup_type).to eql(v) + end + end + + %w{automatic manual disabled}.each do |type| + it "it coerces startup_type property #{type} to :#{type}" do + resource.startup_type type + expect(resource.startup_type).to eql(type.to_sym) + end + end + + [:automatic, :manual, :disabled].each do |type| + it "supports setting startup_type property to #{type.inspect}" do + resource.startup_type type + expect(resource.startup_type).to eql(type) + end end it "allows the action to be 'configure_startup'" do @@ -61,7 +84,7 @@ describe Chef::Resource::WindowsService, "initialize" do # Properties that are Strings %i{description service_name binary_path_name load_order_group dependencies run_as_user run_as_password display_name}.each do |prop| - it "support setting #{prop}" do + it "support setting #{prop} property with a String" do resource.send("#{prop}=", "some value") expect(resource.send(prop)).to eq("some value") end @@ -69,7 +92,7 @@ describe Chef::Resource::WindowsService, "initialize" do # Properties that are Integers %i{desired_access error_control service_type}.each do |prop| - it "support setting #{prop}" do + it "support setting #{prop} property with an Integer" do resource.send("#{prop}=", 1) expect(resource.send(prop)).to eq(1) end |