diff options
author | Tim Smith <tsmith@chef.io> | 2020-08-17 22:25:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-17 22:25:25 -0700 |
commit | dae6eb27b8ca6f2c6e00c8bf11babf2302d59b63 (patch) | |
tree | 5aa00979e5a8392512aa0f66ce0cd087e8ad8dfd | |
parent | 0cbd5cb3b4891c087cfda6ea69e539c0f041ab39 (diff) | |
parent | b464890d6a717c488c3f7ad83e0ff06034278627 (diff) | |
download | chef-dae6eb27b8ca6f2c6e00c8bf11babf2302d59b63.tar.gz |
Merge pull request #10315 from chef/win_feature
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/resource/windows_feature_powershell.rb | 8 | ||||
-rw-r--r-- | spec/unit/resource/windows_feature_powershell_spec.rb | 34 |
2 files changed, 36 insertions, 6 deletions
diff --git a/lib/chef/resource/windows_feature_powershell.rb b/lib/chef/resource/windows_feature_powershell.rb index 6e4e0e5ff5..0fcd52241a 100644 --- a/lib/chef/resource/windows_feature_powershell.rb +++ b/lib/chef/resource/windows_feature_powershell.rb @@ -163,8 +163,12 @@ class Chef # @return [Array] features the user has requested to install which need installation def features_to_install - # the intersection of the features to install & disabled features are what needs installing - @install ||= new_resource.feature_name & node["powershell_features_cache"]["disabled"] + # the intersection of the features to install & disabled/removed features are what needs installing + @features_to_install ||= begin + features = node["powershell_features_cache"]["disabled"] + features |= node["powershell_features_cache"]["removed"] if new_resource.source + new_resource.feature_name & features + end end # @return [Array] features the user has requested to remove which need removing diff --git a/spec/unit/resource/windows_feature_powershell_spec.rb b/spec/unit/resource/windows_feature_powershell_spec.rb index b727d8dfb5..ef2da38334 100644 --- a/spec/unit/resource/windows_feature_powershell_spec.rb +++ b/spec/unit/resource/windows_feature_powershell_spec.rb @@ -22,6 +22,7 @@ describe Chef::Resource::WindowsFeaturePowershell do let(:events) { Chef::EventDispatch::Dispatcher.new } let(:run_context) { Chef::RunContext.new(node, {}, events) } let(:resource) { Chef::Resource::WindowsFeaturePowershell.new(%w{SNMP DHCP}, run_context) } + let(:provider) { resource.provider_for_action(:install) } it "sets resource name as :windows_feature_powershell" do expect(resource.resource_name).to eql(:windows_feature_powershell) @@ -36,10 +37,6 @@ describe Chef::Resource::WindowsFeaturePowershell do expect(resource.feature_name).to eql(%w{snmp dhcp}) end - it "sets the default action as :install" do - expect(resource.action).to eql([:install]) - end - it "supports :delete, :install, :remove actions" do expect { resource.action :delete }.not_to raise_error expect { resource.action :install }.not_to raise_error @@ -69,4 +66,33 @@ describe Chef::Resource::WindowsFeaturePowershell do resource.feature_name "SNMP" expect(resource.feature_name).to eql(["SNMP"]) end + + it "install a single feature" do + resource.feature_name "snmp" + expect { resource.action :install }.not_to raise_error + end + + it "install multi feature" do + resource.feature_name "SNMP, DHCP" + expect { resource.action :install }.not_to raise_error + end + + it "does not attempt to install features that have been removed" do + node.default["powershell_features_cache"] ||= {} + node.default["powershell_features_cache"]["disabled"] = ["dhcp"] + node.default["powershell_features_cache"]["removed"] = ["snmp"] + resource.feature_name "dhcp, snmp" + + expect(provider.features_to_install).to eq(["dhcp"]) + end + + it "attempts to install features that have been removed when source is set" do + node.default["powershell_features_cache"] ||= {} + node.default["powershell_features_cache"]["disabled"] = ["dhcp"] + node.default["powershell_features_cache"]["removed"] = ["snmp"] + resource.feature_name "dhcp, snmp" + resource.source 'D:\\sources\\sxs' + + expect(provider.features_to_install).to eq(%w{dhcp snmp}) + end end |