summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-12-11 11:57:54 -0800
committerGitHub <noreply@github.com>2018-12-11 11:57:54 -0800
commitb8b2289826155371ee626e1e4dddb2e926360551 (patch)
tree7c1d9962c0b3183c7def58c207d1ccbd77c234d6
parent3a9fafbeec1735cd614f5397d21e48812ff551a2 (diff)
parent321086f8e5f097e96d3eb59c2f292ab67ce41d48 (diff)
downloadchef-b8b2289826155371ee626e1e4dddb2e926360551.tar.gz
Merge pull request #7977 from MsysTechnologiesllc/Kapil/MSYS-919_now_user_can_use_tagged_method_in_both_only_if_and_not_if
Allow the use of tagged?(tags) method in both only_if and not_if blocks
-rw-r--r--lib/chef/dsl/universal.rb7
-rw-r--r--lib/chef/recipe.rb15
-rw-r--r--spec/unit/resource_spec.rb23
3 files changed, 30 insertions, 15 deletions
diff --git a/lib/chef/dsl/universal.rb b/lib/chef/dsl/universal.rb
index f3b79b1d60..0856012cbd 100644
--- a/lib/chef/dsl/universal.rb
+++ b/lib/chef/dsl/universal.rb
@@ -47,6 +47,13 @@ class Chef
include Chef::Mixin::PowershellExec
include Chef::Mixin::PowershellOut
include Chef::Mixin::ShellOut
+
+ def tagged?(*tags)
+ tags.each do |tag|
+ return false unless run_context.node.tags.include?(tag)
+ end
+ true
+ end
end
end
end
diff --git a/lib/chef/recipe.rb b/lib/chef/recipe.rb
index f00b211630..209b7faa74 100644
--- a/lib/chef/recipe.rb
+++ b/lib/chef/recipe.rb
@@ -71,21 +71,6 @@ class Chef
run_context.node.tag(*tags)
end
- # Returns true if the node is tagged with *all* of the supplied +tags+.
- #
- # === Parameters
- # tags<Array>:: A list of tags
- #
- # === Returns
- # true<TrueClass>:: If all the parameters are present
- # false<FalseClass>:: If any of the parameters are missing
- def tagged?(*tags)
- tags.each do |tag|
- return false unless run_context.node.tags.include?(tag)
- end
- true
- end
-
# Removes the list of tags from the node.
#
# === Parameters
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 921ca6d33e..7793b82034 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -1204,4 +1204,27 @@ describe Chef::Resource do
klass.provides(:test_resource, allow_cookbook_override: false)
end
end
+
+ describe "tagged" do
+ let(:recipe) do
+ Chef::Recipe.new("hjk", "test", run_context)
+ end
+
+ describe "with the default node object" do
+ let(:node) { Chef::Node.new }
+
+ it "should return false for any tags" do
+ expect(resource.tagged?("foo")).to be(false)
+ end
+ end
+
+ it "should return true from tagged? if node is tagged" do
+ recipe.tag "foo"
+ expect(resource.tagged?("foo")).to be(true)
+ end
+
+ it "should return false from tagged? if node is not tagged" do
+ expect(resource.tagged?("foo")).to be(false)
+ end
+ end
end