diff options
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/resource/macosx_service.rb | 37 | ||||
-rw-r--r-- | spec/unit/resource/service_spec.rb | 159 | ||||
-rw-r--r-- | spec/unit/resource/windows_service_spec.rb | 43 |
3 files changed, 142 insertions, 97 deletions
diff --git a/spec/unit/resource/macosx_service.rb b/spec/unit/resource/macosx_service.rb new file mode 100644 index 0000000000..aebe5e0dd3 --- /dev/null +++ b/spec/unit/resource/macosx_service.rb @@ -0,0 +1,37 @@ +# +# Author:: Tim Smith (tsmith@chef.io>) +# Copyright:: Copyright 2018, Chef Software Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require "spec_helper" + +describe Chef::Resource::MacosxService do + let(:resource) { Chef::Resource::MacosxService.new("chef") } + + it "sets the resource_name to :macosx_service" do + expect(resource.resource_name).to eql(:macosx_service) + end + + it "accepts a String for the session_type property" do + resource.session_type "foo" + expect(resource.session_type).to eql("foo") + end + + it "accepts a String for the plist property" do + resource.plist "foo" + expect(resource.plist).to eql("foo") + end +end diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb index 963c2b2d89..7c2b46a0dc 100644 --- a/spec/unit/resource/service_spec.rb +++ b/spec/unit/resource/service_spec.rb @@ -1,7 +1,7 @@ # # Author:: AJ Christensen (<aj@hjksolutions.com>) # Author:: Tyler Cloke (<tyler@chef.io>) -# Copyright:: Copyright 2008-2017, Chef Software Inc. +# Copyright:: Copyright 2008-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,7 +26,7 @@ describe Chef::Resource::Service do expect(resource.provider).to eq(nil) end - it "sets the service_name to the first argument to new" do + it "sets the service_name property as the name_property" do expect(resource.service_name).to eql("chef") end @@ -45,16 +45,17 @@ describe Chef::Resource::Service do expect { resource.action :unmask }.not_to raise_error end - it "sets the pattern to be the service name by default" do - expect(resource.pattern).to eql("chef") + it "Uses the service_name property as the default for the pattern property" do + resource.service_name "something" + expect(resource.pattern).to eql("something") end - it "accepts a string for the service name" do + it "accepts a String for the service name property" do resource.service_name "something" expect(resource.service_name).to eql("something") end - it "accepts a string for the service pattern" do + it "accepts a String for the service pattern" do resource.pattern ".*" expect(resource.pattern).to eql(".*") end @@ -65,127 +66,119 @@ describe Chef::Resource::Service do end.to raise_error(ArgumentError) end - it "accepts a string for the service start command" do - resource.start_command "/etc/init.d/chef start" - expect(resource.start_command).to eql("/etc/init.d/chef start") - end - - it "does not accept a regexp for the service start command" do - expect do - resource.start_command /.*/ - end.to raise_error(ArgumentError) - end - - it "accepts a string for the service stop command" do - resource.stop_command "/etc/init.d/chef stop" - expect(resource.stop_command).to eql("/etc/init.d/chef stop") - end - - it "does not accept a regexp for the service stop command" do - expect do - resource.stop_command /.*/ - end.to raise_error(ArgumentError) - end - - it "accepts a string for the service status command" do - resource.status_command "/etc/init.d/chef status" - expect(resource.status_command).to eql("/etc/init.d/chef status") - end - - it "does not accept a regexp for the service status command" do - expect do - resource.status_command /.*/ - end.to raise_error(ArgumentError) - end - - it "accepts a string for the service restart command" do - resource.restart_command "/etc/init.d/chef restart" - expect(resource.restart_command).to eql("/etc/init.d/chef restart") + it "accepts a String for the user property" do + resource.user "fakey_fakerton" + expect(resource.user).to eql("fakey_fakerton") end - it "does not accept a regexp for the service restart command" do - expect do - resource.restart_command /.*/ - end.to raise_error(ArgumentError) + it "accepts an Array for the run_levels property" do + resource.run_levels ["foo"] + expect(resource.run_levels).to eql(["foo"]) end - it "accepts a string for the service reload command" do - resource.reload_command "/etc/init.d/chef reload" - expect(resource.reload_command).to eql("/etc/init.d/chef reload") - end - - it "does not accept a regexp for the service reload command" do - expect do - resource.reload_command /.*/ - end.to raise_error(ArgumentError) + it "accepts a Hash for the parameters property" do + param_hash = { something: nil } + resource.parameters param_hash + expect(resource.parameters).to eql(param_hash) end - it "accepts a string for the service init command" do + it "accepts a String for the init_command property" do resource.init_command "/etc/init.d/chef" expect(resource.init_command).to eql("/etc/init.d/chef") end - it "does not accept a regexp for the service init command" do + it "does not accept a regexp for the init_command property" do expect do resource.init_command /.*/ end.to raise_error(ArgumentError) end - it "accepts an array for options" do + it "accepts an array for options property" do resource.options ["-r", "-s"] expect(resource.options).to eql(["-r", "-s"]) end - it "accepts a string for options" do + it "accepts a String for options property" do resource.options "-r" expect(resource.options).to eql(["-r"]) end - it "accepts a string with multiple flags for options" do + it "accepts a String with multiple flags for options property" do resource.options "-r -s" expect(resource.options).to eql(["-r", "-s"]) end - it "does not accept a boolean for options" do + it "does not accept a boolean for options property" do expect do resource.options true end.to raise_error(ArgumentError) end - %w{enabled running}.each do |attrib| - it "accepts true for #{attrib}" do - resource.send(attrib, true) - expect(resource.send(attrib)).to eql(true) + %w{restart_command start_command stop_command status_command reload_command}.each do |prop| + it "accepts a String for the #{prop} property" do + resource.send(prop, "service foo bar") + expect(resource.send(prop)).to eql("service foo bar") end - it "accepts false for #{attrib}" do - resource.send(attrib, false) - expect(resource.send(attrib)).to eql(false) + it "accepts false for #{prop} property" do + resource.send(prop, false) + expect(resource.send(prop)).to eql(false) end - it "does not accept a string for #{attrib}" do - expect { resource.send(attrib, "poop") }.to raise_error(ArgumentError) + it "does not accept a regexp for the #{prop} property" do + expect { resource.send(prop, /.*/) }.to raise_error(ArgumentError) end + end - it "defaults all the feature support to nil" do - support_hash = { status: nil, restart: nil, reload: nil } - expect(resource.supports).to eq(support_hash) + it "accepts a String for priority property" do + resource.priority "1" + expect(resource.priority).to eql("1") + end + + it "accepts an Integer for priority property" do + resource.priority 1 + expect(resource.priority).to eql(1) + end + + it "accepts an Integer for timeout property" do + resource.timeout 1 + expect(resource.timeout).to eql(1) + end + + %w{enabled running}.each do |prop| + it "accepts true for #{prop} property" do + resource.send(prop, true) + expect(resource.send(prop)).to eql(true) end - it "allows you to set what features this resource supports as a array" do - support_array = [ :status, :restart ] - support_hash = { status: true, restart: true } - resource.supports(support_array) - expect(resource.supports).to eq(support_hash) + it "accepts false for #{prop} property" do + resource.send(prop, false) + expect(resource.send(prop)).to eql(false) end - it "allows you to set what features this resource supports as a hash" do - support_hash = { status: true, restart: true } - resource.supports(support_hash) - expect(resource.supports).to eq(support_hash) + it "does not accept a String for #{prop} property" do + expect { resource.send(prop, "poop") }.to raise_error(ArgumentError) end end + it "defaults all the feature support to nil" do + support_hash = { status: nil, restart: nil, reload: nil } + expect(resource.supports).to eq(support_hash) + end + + it "allows you to set what features this resource supports as an array" do + support_array = [ :status, :restart ] + support_hash = { status: true, restart: true } + resource.supports(support_array) + expect(resource.supports).to eq(support_hash) + end + + it "allows you to set what features this resource supports as a hash" do + support_hash = { status: true, restart: true } + resource.supports(support_hash) + expect(resource.supports).to eq(support_hash) + end + describe "when it has pattern and supports" do before do resource.service_name("superfriend") @@ -199,7 +192,7 @@ describe Chef::Resource::Service do expect(state[:running]).to eql(false) end - it "returns the service name as its identity" do + it "returns the service_name property as its identity" do expect(resource.identity).to eq("superfriend") end end diff --git a/spec/unit/resource/windows_service_spec.rb b/spec/unit/resource/windows_service_spec.rb index 8648b52a17..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"); @@ -19,14 +19,6 @@ require "spec_helper" describe Chef::Resource::WindowsService, "initialize" do - static_provider_resolution( - resource: Chef::Resource::WindowsService, - provider: Chef::Provider::Service::Windows, - os: "windows", - name: :windows_service, - action: :start - ) - let(:resource) { Chef::Resource::WindowsService.new("fakey_fakerton") } it "sets the resource_name to :windows_service" do @@ -56,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 @@ -69,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 @@ -77,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 |