diff options
author | Kapil Chouhan <kapil.chouhan@msystechnologies.com> | 2018-11-22 11:59:09 +0000 |
---|---|---|
committer | Kapil Chouhan <kapil.chouhan@msystechnologies.com> | 2018-11-29 12:57:12 +0000 |
commit | 321086f8e5f097e96d3eb59c2f292ab67ce41d48 (patch) | |
tree | 9378f22273e7eb72bedb383c6b03f17740d20391 | |
parent | 5c436ac98fd9a5dd78e243616123650217c90419 (diff) | |
download | chef-321086f8e5f097e96d3eb59c2f292ab67ce41d48.tar.gz |
now user can use tagged method in both only_if and not_if
Signed-off-by: Kapil Chouhan <kapil.chouhan@msystechnologies.com>
-rw-r--r-- | lib/chef/dsl/universal.rb | 7 | ||||
-rw-r--r-- | lib/chef/recipe.rb | 15 | ||||
-rw-r--r-- | spec/unit/resource_spec.rb | 23 |
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 |