diff options
author | Tim Smith <tsmith@chef.io> | 2018-05-15 15:11:28 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-05-15 15:11:28 -0700 |
commit | 6c9e1e44a1a13260cff9d027649055cce05493bd (patch) | |
tree | 4e3c862615197275cfc543aa04bad475042a548f /spec | |
parent | cc0d8c423811a96bdbf4835384ed906c0325629f (diff) | |
download | chef-6c9e1e44a1a13260cff9d027649055cce05493bd.tar.gz |
Add additional unit tests for resource actions/properties
Fill in some missing coverage here so we can refactor with confidence.
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/resource/windows_ad_join.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource/windows_auto_run_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource/windows_env_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/resource/windows_feature.rb | 21 | ||||
-rw-r--r-- | spec/unit/resource/windows_feature_dism.rb | 26 | ||||
-rw-r--r-- | spec/unit/resource/windows_feature_powershell.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource/windows_font_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource/windows_pagefile_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/resource/windows_path_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource/windows_printer_port_spec.rb | 20 | ||||
-rw-r--r-- | spec/unit/resource/windows_printer_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/resource/yum_repository_spec.rb | 47 | ||||
-rw-r--r-- | spec/unit/resource/zypper_repository_spec.rb | 50 |
13 files changed, 176 insertions, 20 deletions
diff --git a/spec/unit/resource/windows_ad_join.rb b/spec/unit/resource/windows_ad_join.rb index 7fd02c2021..b2c18c7b7e 100644 --- a/spec/unit/resource/windows_ad_join.rb +++ b/spec/unit/resource/windows_ad_join.rb @@ -24,7 +24,7 @@ describe Chef::Resource::WindowsAdJoin do expect(resource.resource_name).to eql(:windows_ad_join) end - it "sets the domain_name as its name" do + it "the domain_name property is the name_property" do expect(resource.domain_name).to eql("example.com") end diff --git a/spec/unit/resource/windows_auto_run_spec.rb b/spec/unit/resource/windows_auto_run_spec.rb index c92bbb2f98..c0c3628008 100644 --- a/spec/unit/resource/windows_auto_run_spec.rb +++ b/spec/unit/resource/windows_auto_run_spec.rb @@ -28,7 +28,7 @@ describe Chef::Resource::WindowsAutorun do expect(resource.action).to eql([:create]) end - it "sets the program_name property as its name" do + it "the program_name property is the name_property" do expect(resource.program_name).to eql("some_path") end it "supports :machine and :user in the root property" do diff --git a/spec/unit/resource/windows_env_spec.rb b/spec/unit/resource/windows_env_spec.rb index 776e4f7cd5..1ccb53c041 100644 --- a/spec/unit/resource/windows_env_spec.rb +++ b/spec/unit/resource/windows_env_spec.rb @@ -28,10 +28,6 @@ describe Chef::Resource::WindowsEnv do expect(resource).to be_a_kind_of(Chef::Resource::WindowsEnv) end - it "has a name" do - expect(resource.name).to eql("FOO") - end - it "has a default action of 'create'" do expect(resource.action).to eql([:create]) end @@ -46,7 +42,7 @@ describe Chef::Resource::WindowsEnv do end end - it "uses the object name as the key_name by default" do + it "the key_name property is the name_property" do expect(resource.key_name).to eql("FOO") end diff --git a/spec/unit/resource/windows_feature.rb b/spec/unit/resource/windows_feature.rb index c8b8587ed8..372cd42166 100644 --- a/spec/unit/resource/windows_feature.rb +++ b/spec/unit/resource/windows_feature.rb @@ -28,10 +28,29 @@ describe Chef::Resource::WindowsFeature do expect(resource.action).to eql([:install]) end - it "sets the feature_name property as its name" do + it "the feature_name property is the name_property" do expect(resource.feature_name).to eql("SNMP") end + it "all property defaults to false" do + expect(resource.all).to eql(false) + end + + it "management_tools property defaults to false" do + expect(resource.management_tools).to eql(false) + end + + it "timeout property defaults to 600" do + expect(resource.timeout).to eql(600) + end + + it "install_method accepts :windows_feature_dism, :windows_feature_powershell, and :windows_feature_servermanagercmd" do + expect { resource.install_method :windows_feature_dism }.not_to raise_error + expect { resource.install_method :windows_feature_powershell }.not_to raise_error + expect { resource.install_method :windows_feature_servermanagercmd }.not_to raise_error + expect { resource.install_method "windows_feature_servermanagercmd" }.to raise_error(ArgumentError) + end + it "supports :install, :remove, and :delete actions" do expect { resource.action :install }.not_to raise_error expect { resource.action :remove }.not_to raise_error diff --git a/spec/unit/resource/windows_feature_dism.rb b/spec/unit/resource/windows_feature_dism.rb index 4f973f7e82..4ed8f68a2a 100644 --- a/spec/unit/resource/windows_feature_dism.rb +++ b/spec/unit/resource/windows_feature_dism.rb @@ -18,7 +18,10 @@ require "spec_helper" describe Chef::Resource::WindowsFeatureDism do - let(:resource) { Chef::Resource::WindowsFeatureDism.new(%w{SNMP DHCP}) } + let(:node) { Chef::Node.new } + let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:run_context) { Chef::RunContext.new(node, {}, events) } + let(:resource) { Chef::Resource::WindowsFeatureDism.new(%w{SNMP DHCP}, run_context) } it "sets resource name as :windows_feature_dism" do expect(resource.resource_name).to eql(:windows_feature_dism) @@ -28,20 +31,35 @@ describe Chef::Resource::WindowsFeatureDism do expect(resource.action).to eql([:install]) end - it "sets the feature_name property as its name property" do + it "sets the feature_name property as its name_property" do + node.automatic[:platform_version] = "6.2" expect(resource.feature_name).to eql(%w{snmp dhcp}) end - it "coerces comma separated lists of features to a lowercase array" do + it "coerces comma separated lists of features to a lowercase array on 2012+" do + node.automatic[:platform_version] = "6.2" resource.feature_name "SNMP, DHCP" expect(resource.feature_name).to eql(%w{snmp dhcp}) end - it "coerces a single feature as a String to a lowercase array" do + it "coerces a single feature as a String to a lowercase array on 2012+" do + node.automatic[:platform_version] = "6.2" resource.feature_name "SNMP" expect(resource.feature_name).to eql(["snmp"]) end + it "coerces comma separated lists of features to an array, but preserves case on < 2012" do + node.automatic[:platform_version] = "6.1" + resource.feature_name "SNMP, DHCP" + expect(resource.feature_name).to eql(%w{SNMP DHCP}) + end + + it "coerces a single feature as a String to an array, but preserves case on < 2012" do + node.automatic[:platform_version] = "6.1" + resource.feature_name "SNMP" + expect(resource.feature_name).to eql(["SNMP"]) + end + it "supports :install, :remove, and :delete actions" do expect { resource.action :install }.not_to raise_error expect { resource.action :remove }.not_to raise_error diff --git a/spec/unit/resource/windows_feature_powershell.rb b/spec/unit/resource/windows_feature_powershell.rb index 5ea226575c..7e62b84d6d 100644 --- a/spec/unit/resource/windows_feature_powershell.rb +++ b/spec/unit/resource/windows_feature_powershell.rb @@ -28,7 +28,7 @@ describe Chef::Resource::WindowsFeaturePowershell do expect(resource.action).to eql([:install]) end - it "sets the feature_name property as its name property" do + it "sets the feature_name property as its name_property" do expect(resource.feature_name).to eql(%w{SNMP DHCP}) end diff --git a/spec/unit/resource/windows_font_spec.rb b/spec/unit/resource/windows_font_spec.rb index a98e3f4a40..3e54570d34 100644 --- a/spec/unit/resource/windows_font_spec.rb +++ b/spec/unit/resource/windows_font_spec.rb @@ -24,7 +24,7 @@ describe Chef::Resource::WindowsFont do expect(resource.resource_name).to eql(:windows_font) end - it "sets the font_name as its name" do + it "the font_name property is the name_property" do expect(resource.font_name).to eql("some_font") end diff --git a/spec/unit/resource/windows_pagefile_spec.rb b/spec/unit/resource/windows_pagefile_spec.rb index dd6353eccb..4e54e87c1f 100644 --- a/spec/unit/resource/windows_pagefile_spec.rb +++ b/spec/unit/resource/windows_pagefile_spec.rb @@ -24,7 +24,7 @@ describe Chef::Resource::WindowsPagefile do expect(resource.resource_name).to eql(:windows_pagefile) end - it "sets the path as its name" do + it "the path property is the name_property" do expect(resource.path).to eql("C:\\pagefile.sys") end @@ -33,6 +33,10 @@ describe Chef::Resource::WindowsPagefile do expect(resource.path).to eql("C:\\pagefile.sys") end + it "automatic_managed property defaults to false" do + expect(resource.automatic_managed).to eql(false) + end + it "sets the default action as :set" do expect(resource.action).to eql([:set]) end diff --git a/spec/unit/resource/windows_path_spec.rb b/spec/unit/resource/windows_path_spec.rb index 8f29a11e4e..efe55d1cb6 100644 --- a/spec/unit/resource/windows_path_spec.rb +++ b/spec/unit/resource/windows_path_spec.rb @@ -25,7 +25,7 @@ describe Chef::Resource::WindowsPath do expect(resource.resource_name).to eql(:windows_path) end - it "sets the path as its name" do + it "the path property is the name_property" do expect(resource.path).to eql("some_path") end diff --git a/spec/unit/resource/windows_printer_port_spec.rb b/spec/unit/resource/windows_printer_port_spec.rb index 6b29c2610a..f09d6752ba 100644 --- a/spec/unit/resource/windows_printer_port_spec.rb +++ b/spec/unit/resource/windows_printer_port_spec.rb @@ -24,10 +24,28 @@ describe Chef::Resource::WindowsPrinterPort do expect(resource.resource_name).to eql(:windows_printer_port) end - it "sets the ipv4_address as its name" do + it "the ipv4_address property is the name_property" do expect(resource.ipv4_address).to eql("63.192.209.236") end + it "port_number property defaults to 9100" do + expect(resource.port_number).to eql(9100) + end + + it "snmp_enabled property defaults to false" do + expect(resource.snmp_enabled).to eql(false) + end + + it "port_protocol property defaults to 1" do + expect(resource.port_protocol).to eql(1) + end + + it "raises an error if port_protocol isn't in 1 or 2" do + expect { resource.port_protocol 1 }.not_to raise_error + expect { resource.port_protocol 2 }.not_to raise_error + expect { resource.port_protocol 3 }.to raise_error(ArgumentError) + end + it "sets the default action as :create" do expect(resource.action).to eql([:create]) end diff --git a/spec/unit/resource/windows_printer_spec.rb b/spec/unit/resource/windows_printer_spec.rb index 5c773005ea..4431479aca 100644 --- a/spec/unit/resource/windows_printer_spec.rb +++ b/spec/unit/resource/windows_printer_spec.rb @@ -24,7 +24,7 @@ describe Chef::Resource::WindowsPrinter do expect(resource.resource_name).to eql(:windows_printer) end - it "sets the device_id as its name" do + it "the device_id property is the name_property" do expect(resource.device_id).to eql("some_printer") end @@ -38,6 +38,14 @@ describe Chef::Resource::WindowsPrinter do expect { resource.action :remove }.to raise_error(ArgumentError) end + it "default property defaults to false" do + expect(resource.default).to eql(false) + end + + it "shared property defaults to false" do + expect(resource.shared).to eql(false) + end + it "raises an error if ipv4_address isn't in X.X.X.X format" do expect { resource.ipv4_address "63.192.209.236" }.not_to raise_error expect { resource.ipv4_address "a.b.c.d" }.to raise_error(ArgumentError) diff --git a/spec/unit/resource/yum_repository_spec.rb b/spec/unit/resource/yum_repository_spec.rb index 353ff7ce23..4db6230a93 100644 --- a/spec/unit/resource/yum_repository_spec.rb +++ b/spec/unit/resource/yum_repository_spec.rb @@ -36,6 +36,43 @@ describe Chef::Resource::YumRepository do expect { resource.repositoryid "foo/bar" }.to raise_error(ArgumentError) end + it "has a default action of :create" do + expect(resource.action).to eql([:create]) + end + + it "supports :create, :remove, :add, :makecache, and :delete actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :add }.not_to raise_error + expect { resource.action :makecache }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :refresh }.to raise_error(ArgumentError) + end + + it "clean_headers property defaults to false" do + expect(resource.clean_headers).to eql(false) + end + + it "clean_metadata property defaults to true" do + expect(resource.clean_metadata).to eql(true) + end + + it "description property defaults to 'Yum Repository'" do + expect(resource.description).to eql("Yum Repository") + end + + it "enabled property defaults to true" do + expect(resource.enabled).to eql(true) + end + + it "make_cache property defaults to true" do + expect(resource.make_cache).to eql(true) + end + + it "mode property defaults to '0644'" do + expect(resource.mode).to eql("0644") + end + it "the timeout property expects numeric Strings" do expect { resource.timeout "123" }.not_to raise_error(ArgumentError) expect { resource.timeout "123foo" }.to raise_error(ArgumentError) @@ -86,6 +123,16 @@ describe Chef::Resource::YumRepository do expect { resource.mirrorlist_expire "never" }.to raise_error(ArgumentError) end + it "accepts the legacy 'url' property" do + resource.url "foo" + expect(resource.baseurl).to eql("foo") + end + + it "accepts the legacy 'keyurl' property" do + resource.keyurl "foo" + expect(resource.gpgkey).to eql("foo") + end + context "on linux", :linux_only do it "resolves to a Noop class when yum is not found" do expect(Chef::Provider::YumRepository).to receive(:which).with("yum").and_return(false) diff --git a/spec/unit/resource/zypper_repository_spec.rb b/spec/unit/resource/zypper_repository_spec.rb index 8f93aecd8e..cff5e2c0fc 100644 --- a/spec/unit/resource/zypper_repository_spec.rb +++ b/spec/unit/resource/zypper_repository_spec.rb @@ -36,11 +36,11 @@ describe Chef::Resource::ZypperRepository do expect { resource.repo_name "foo/bar" }.to raise_error(ArgumentError) end - it "has a default action of create" do + it "has a default action of :create" do expect(resource.action).to eql([:create]) end - it "supports all valid actions" do + it "supports :create, :remove, :add, and :refresh actions" do expect { resource.action :add }.not_to raise_error expect { resource.action :remove }.not_to raise_error expect { resource.action :create }.not_to raise_error @@ -48,6 +48,52 @@ describe Chef::Resource::ZypperRepository do expect { resource.action :delete }.to raise_error(ArgumentError) end + it "type property defaults to 'NONE'" do + expect(resource.type).to eql("NONE") + end + + it "enabled property defaults to true" do + expect(resource.enabled).to eql(true) + end + + it "autorefresh property defaults to true" do + expect(resource.autorefresh).to eql(true) + end + + it "gpgcheck property defaults to true" do + expect(resource.gpgcheck).to eql(true) + end + + it "keeppackages property defaults to false" do + expect(resource.keeppackages).to eql(false) + end + + it "priority property defaults to 99" do + expect(resource.priority).to eql(99) + end + + it "mode property defaults to '0644'" do + expect(resource.mode).to eql("0644") + end + + it "refresh_cache property defaults to true" do + expect(resource.refresh_cache).to eql(true) + end + + it "gpgautoimportkeys property defaults to true" do + expect(resource.gpgautoimportkeys).to eql(true) + end + + it "accepts the legacy 'key' property" do + resource.key "foo" + expect(resource.gpgkey).to eql("foo") + end + + it "accepts the legacy 'uri' property" do + resource.uri "foo" + expect(resource.baseurl).to eql("foo") + end + context "on linux", :linux_only do it "resolves to a Noop class when on non-linux OS" do node.automatic[:os] = "windows" |