summaryrefslogtreecommitdiff
path: root/spec/unit/resource_spec.rb
diff options
context:
space:
mode:
authorXabier de Zuazo <xabier@zuazo.org>2012-12-26 19:58:26 +0100
committerBryan McLellan <btm@opscode.com>2013-06-19 14:18:42 -0700
commit0304062ff84fee4adeb4a313fd8065239cf865c4 (patch)
tree84ba762e76ad0512c9960e10f562dc321ad4de1e /spec/unit/resource_spec.rb
parent31421866cd4ac9aee5f8960a40e48cfcf10617b2 (diff)
downloadchef-0304062ff84fee4adeb4a313fd8065239cf865c4.tar.gz
[CHEF-972] resource action should have higher precedence than only_if/not_if (:nothing action)
Diffstat (limited to 'spec/unit/resource_spec.rb')
-rw-r--r--spec/unit/resource_spec.rb102
1 files changed, 101 insertions, 1 deletions
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index dd4f3611f9..a25f180cf7 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -459,7 +459,6 @@ describe Chef::Resource do
end
describe "when invoking its action" do
-
before do
@resource = Chef::Resource.new("provided", @run_context)
@resource.provider = Chef::Provider::SnakeOil
@@ -529,6 +528,107 @@ describe Chef::Resource do
end
+ describe "should_skip?" do
+ before do
+ @resource = Chef::Resource::Cat.new("sugar", @run_context)
+ end
+
+ it "should return false by default" do
+ @resource.should_skip?(:purr).should be_false
+ end
+
+ it "should return false when if_only is met" do
+ @resource.only_if { true }
+ @resource.should_skip?(:purr).should be_false
+ end
+
+ it "should return true when if_only is not met" do
+ @resource.only_if { false }
+ @resource.should_skip?(:purr).should be_true
+ end
+
+ it "should return true when not_if is met" do
+ @resource.not_if { true }
+ @resource.should_skip?(:purr).should be_true
+ end
+
+ it "should return false when if_only is not met" do
+ @resource.not_if { false }
+ @resource.should_skip?(:purr).should be_false
+ end
+
+ it "should return true when if_only is met but also not_if is met" do
+ @resource.only_if { true }
+ @resource.not_if { true }
+ @resource.should_skip?(:purr).should be_true
+ end
+
+ it "should return true when one of multiple if_only's is not met" do
+ @resource.only_if { true }
+ @resource.only_if { false }
+ @resource.only_if { true }
+ @resource.should_skip?(:purr).should be_true
+ end
+
+ it "should return true when one of multiple not_if's is met" do
+ @resource.not_if { false }
+ @resource.not_if { true }
+ @resource.not_if { false }
+ @resource.should_skip?(:purr).should be_true
+ end
+
+ it "should return true when action is :nothing" do
+ @resource.should_skip?(:nothing).should be_true
+ end
+
+ it "should return true when action is :nothing ignoring only_if/not_if conditionals" do
+ @resource.only_if { true }
+ @resource.not_if { false }
+ @resource.should_skip?(:nothing).should be_true
+ end
+
+ end
+
+ describe "when resource action is :nothing" do
+ before do
+ @resource1 = Chef::Resource::Cat.new("sugar", @run_context)
+ @resource1.action = :nothing
+
+ @node.automatic_attrs[:platform] = "fubuntu"
+ @node.automatic_attrs[:platform_version] = '10.04'
+ end
+
+ it "should not run only_if/not_if conditionals (CHEF-972)" do
+ snitch_var1 = 0
+ @resource1.only_if { snitch_var1 = 1 }
+ @resource1.not_if { snitch_var1 = 2 }
+ @resource1.run_action(:nothing)
+ snitch_var1.should == 0
+ end
+
+ it "should run only_if/not_if conditionals when notified to run another action (CHEF-972)" do
+ snitch_var1 = snitch_var2 = 0
+ @runner = Chef::Runner.new(@run_context)
+ Chef::Platform.set(
+ :resource => :cat,
+ :provider => Chef::Provider::SnakeOil
+ )
+
+ @resource1.only_if { snitch_var1 = 1 }
+ @resource1.not_if { snitch_var2 = 2 }
+ @resource2 = Chef::Resource::Cat.new("coffee", @run_context)
+ @resource2.notifies :purr, @resource1
+ @resource2.action = :purr
+
+ @run_context.resource_collection << @resource1
+ @run_context.resource_collection << @resource2
+ @runner.converge
+
+ snitch_var1.should == 1
+ snitch_var2.should == 2
+ end
+ end
+
describe "building the platform map" do
it 'adds mappings for a single platform' do