summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-05-28 17:12:51 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-05-28 17:12:51 -0700
commit0ca2b3cc22a8d8581db2f44ed87743709ef0ec5e (patch)
tree820449dd6b5ff6525b912707785cd8b28c7ae42b
parent32de6ae832ca03a51554d8ff4158b60d9095cc31 (diff)
downloadchef-lcg/refactor-chocolatey-feature.tar.gz
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--spec/unit/policy_builder/dynamic_spec.rb2
-rw-r--r--spec/unit/resource/chocolatey_feature_spec.rb65
2 files changed, 65 insertions, 2 deletions
diff --git a/spec/unit/policy_builder/dynamic_spec.rb b/spec/unit/policy_builder/dynamic_spec.rb
index f014cd9f2e..3dbe033189 100644
--- a/spec/unit/policy_builder/dynamic_spec.rb
+++ b/spec/unit/policy_builder/dynamic_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@chef.io>)
-# Copyright:: Copyright 2014-2016, Chef Software, Inc.
+# Copyright:: Copyright 2014-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/unit/resource/chocolatey_feature_spec.rb b/spec/unit/resource/chocolatey_feature_spec.rb
index 474a6f112e..e1839a30a6 100644
--- a/spec/unit/resource/chocolatey_feature_spec.rb
+++ b/spec/unit/resource/chocolatey_feature_spec.rb
@@ -19,7 +19,13 @@ require "spec_helper"
describe Chef::Resource::ChocolateyFeature do
- let(:resource) { Chef::Resource::ChocolateyFeature.new("fakey_fakerton") }
+ let(:node) { Chef::Node.new }
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
+ let(:resource) { Chef::Resource::ChocolateyFeature.new("fakey_fakerton", run_context) }
+ let(:provider) { resource.provider_for_action(:set) }
+ let(:current_resource) { Chef::Resource::ChocolateyFeature.new("fakey_fakerton") }
+
let(:config) do
<<-CONFIG
<?xml version="1.0" encoding="utf-8"?>
@@ -40,6 +46,9 @@ describe Chef::Resource::ChocolateyFeature do
# we save off the ENV and set ALLUSERSPROFILE so these specs will work on *nix and non-C drive Windows installs
before(:each) do
+ provider # vivify before mocking
+ allow(resource).to receive(:provider_for_action).and_return(provider)
+ allow(resource).to receive(:dup).and_return(current_resource)
@original_env = ENV.to_hash
ENV["ALLUSERSPROFILE"] = 'C:\ProgramData'
end
@@ -85,4 +94,58 @@ describe Chef::Resource::ChocolateyFeature do
expect { resource.fetch_feature_element("foo") }.not_to raise_error
end
end
+
+ describe "#load_current_resource" do
+ it "sets the state to :enabled when the XML enabled property is true" do
+ allow(current_resource).to receive(:fetch_feature_element).with("fakey_fakerton").and_return("true")
+ provider.load_current_resource
+ expect(current_resource.state).to be :enabled
+ end
+
+ it "sets the state to :disabled when the XML enabled property is false" do
+ allow(current_resource).to receive(:fetch_feature_element).with("fakey_fakerton").and_return("false")
+ provider.load_current_resource
+ expect(current_resource.state).to be :disabled
+ end
+
+ it "sets the current_resource to nil when the property is not present" do
+ allow(current_resource).to receive(:fetch_feature_element).with("fakey_fakerton").and_return(nil)
+ provider.load_current_resource
+ expect(provider.current_resource).to be nil
+ end
+ end
+
+ describe "run_action(:set)" do
+ it "when it is disabled, it enables it correctly" do
+ resource.state :enabled
+ allow(current_resource).to receive(:fetch_feature_element).with("fakey_fakerton").and_return("false")
+ expect(provider).to receive(:shell_out!).with("C:\\ProgramData\\chocolatey\\bin\\choco feature enable --name fakey_fakerton")
+ resource.run_action(:set)
+ expect(resource.updated_by_last_action?).to be true
+ end
+
+ it "when it is enabled, it is idempotent when trying to enable" do
+ resource.state :enabled
+ allow(current_resource).to receive(:fetch_feature_element).with("fakey_fakerton").and_return("true")
+ expect(provider).not_to receive(:shell_out!)
+ resource.run_action(:set)
+ expect(resource.updated_by_last_action?).to be false
+ end
+
+ it "when it is disabled, it is idempotent when trying to disable" do
+ resource.state :disabled
+ allow(current_resource).to receive(:fetch_feature_element).with("fakey_fakerton").and_return("false")
+ expect(provider).not_to receive(:shell_out!)
+ resource.run_action(:set)
+ expect(resource.updated_by_last_action?).to be false
+ end
+
+ it "when it is enabled, it is idempotent when trying to enable" do
+ resource.state :disabled
+ allow(current_resource).to receive(:fetch_feature_element).with("fakey_fakerton").and_return("true")
+ expect(provider).to receive(:shell_out!).with("C:\\ProgramData\\chocolatey\\bin\\choco feature disable --name fakey_fakerton")
+ resource.run_action(:set)
+ expect(resource.updated_by_last_action?).to be true
+ end
+ end
end