diff options
author | Gary Ewan Park <gep13@gep13.co.uk> | 2019-06-05 07:57:36 +0100 |
---|---|---|
committer | Gary Ewan Park <gep13@gep13.co.uk> | 2019-06-05 08:04:27 +0100 |
commit | 5a1daf0c5a0899a53ce181834cd851192fb89c7c (patch) | |
tree | 2d0c63e7f8855f28eb4219c488fd06ee2c59f7e3 | |
parent | 1671fe7bbaf122a2d4e13e2d3ac432b916d26a5a (diff) | |
download | chef-5a1daf0c5a0899a53ce181834cd851192fb89c7c.tar.gz |
Address PR review feedback
Signed-off-by: Gary Ewan Park <gep13@gep13.co.uk>
-rw-r--r-- | lib/chef/resource/chocolatey_source.rb | 11 | ||||
-rw-r--r-- | spec/unit/resource/chocolatey_source_spec.rb | 12 |
2 files changed, 11 insertions, 12 deletions
diff --git a/lib/chef/resource/chocolatey_source.rb b/lib/chef/resource/chocolatey_source.rb index c9b3316300..2b358a22f7 100644 --- a/lib/chef/resource/chocolatey_source.rb +++ b/lib/chef/resource/chocolatey_source.rb @@ -17,7 +17,6 @@ class Chef class Resource class ChocolateySource < Chef::Resource - preview_resource true resource_name :chocolatey_source description "Use the chocolatey_source resource to add or remove Chocolatey sources." @@ -41,7 +40,7 @@ class Chef property :priority, Integer, default: 0, description: "The priority level of the source." - property :source_state, [TrueClass, FalseClass], default: false, desired_state: false, skip_docs: true + property :disabled, [TrueClass, FalseClass], default: false, desired_state: false, skip_docs: true load_current_value do element = fetch_source_element(source_name) @@ -53,13 +52,13 @@ class Chef admin_only element["adminOnly"] == "true" allow_self_service element["selfService"] == "true" priority element["priority"].to_i - source_state element["disabled"] == "true" + disabled element["disabled"] == "true" end # @param [String] id the source name # @return [REXML::Attributes] finds the source element with the def fetch_source_element(id) - require "rexml/document" + require "rexml/document" unless defined?(REXML::Document) config_file = "#{ENV['ALLUSERSPROFILE']}\\chocolatey\\config\\chocolatey.config" raise "Could not find the Chocolatey config at #{config_file}!" unless ::File.exist?(config_file) @@ -92,7 +91,7 @@ class Chef action :disable do description "Disables a Chocolatey source." - if current_resource.source_state != true + if current_resource.disabled != true converge_by("disable Chocolatey source '#{new_resource.source_name}'") do shell_out!(choco_cmd("disable")) end @@ -102,7 +101,7 @@ class Chef action :enable do description "Enables a Chocolatey source." - if current_resource.source_state == true + if current_resource.disabled == true converge_by("enable Chocolatey source '#{new_resource.source_name}'") do shell_out!(choco_cmd("enable")) end diff --git a/spec/unit/resource/chocolatey_source_spec.rb b/spec/unit/resource/chocolatey_source_spec.rb index 455e94c6cb..60bd773594 100644 --- a/spec/unit/resource/chocolatey_source_spec.rb +++ b/spec/unit/resource/chocolatey_source_spec.rb @@ -97,22 +97,22 @@ describe Chef::Resource::ChocolateySource do end describe "#load_current_resource" do - it "sets the source_state to true when the XML disabled property is true" do + it "sets disabled to true when the XML disabled property is true" do allow(current_resource).to receive(:fetch_source_element).with("fakey_fakerton").and_return(OpenStruct.new(disabled: "true")) disable_provider.load_current_resource - expect(current_resource.source_state).to be true + expect(current_resource.disabled).to be true end - it "sets the source_state to false when the XML disabled property is false" do + it "sets disabled to false when the XML disabled property is false" do allow(current_resource).to receive(:fetch_source_element).with("fakey_fakerton").and_return(OpenStruct.new(disabled: "false")) enable_provider.load_current_resource - expect(current_resource.source_state).to be false + expect(current_resource.disabled).to be false end end describe "run_action(:enable)" do it "when source is disabled, it enables it correctly" do - resource.source_state true + resource.disabled true allow(current_resource).to receive(:fetch_source_element).with("fakey_fakerton").and_return(OpenStruct.new(disabled: "true")) expect(enable_provider).to receive(:shell_out!).with("C:\\ProgramData\\chocolatey\\bin\\choco source enable -n \"fakey_fakerton\"") resource.run_action(:enable) @@ -120,7 +120,7 @@ describe Chef::Resource::ChocolateySource do end it "when source is enabled, it is idempotent when trying to enable" do - resource.source_state false + resource.disabled false allow(current_resource).to receive(:fetch_source_element).with("fakey_fakerton").and_return(OpenStruct.new(disabled: "false")) resource.run_action(:enable) expect(resource.updated_by_last_action?).to be false |