summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <454857+lamont-granquist@users.noreply.github.com>2022-02-15 12:27:37 -0800
committerGitHub <noreply@github.com>2022-02-15 12:27:37 -0800
commite09cdbdda87215fc88aae711f9dd92e201b591f7 (patch)
treeeba8c0086b0c2997d93ad88f294f5f33b9dd98eb
parent70052630348ab0a4597a1a27b6d6b5ae16cf422d (diff)
parent9c3f1d4871566dc86aff7e3494a41a9fd6814608 (diff)
downloadchef-e09cdbdda87215fc88aae711f9dd92e201b591f7.tar.gz
Merge pull request #12525 from neha-p6/fix_resource_subscribes_spec
-rw-r--r--lib/chef/resource.rb1
-rw-r--r--spec/unit/resource_spec.rb16
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 681927f1d0..f9ab292b83 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -341,6 +341,7 @@ class Chef
def subscribes(action, resources, timing = :delayed)
resources = [resources].flatten
resources.each do |resource|
+ validate_resource_spec!(resource)
if resource.is_a?(String)
resource = UnresolvedSubscribes.new(resource, run_context)
end
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index f20a6d3bc6..f0a624d5db 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -300,27 +300,35 @@ describe Chef::Resource do
end
describe "subscribes" do
+ context "with syntax error in resources parameter" do
+ it "raises an exception immediately" do
+ expect do
+ resource.subscribes(:run, "typo[missing-closing-bracket")
+ end.to raise_error(Chef::Exceptions::InvalidResourceSpecification)
+ end
+ end
+
it "should make resources appear in the actions hash of subscribed nodes" do
- run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee", run_context)
zr = run_context.resource_collection.find(zen_master: "coffee")
resource.subscribes :reload, zr
expect(zr.delayed_notifications.detect { |e| e.resource.name == "funk" && e.action == :reload }).not_to be_nil
end
it "should make resources appear in the actions hash of subscribed nodes" do
- run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee", run_context)
zr = run_context.resource_collection.find(zen_master: "coffee")
resource.subscribes :reload, zr
expect(zr.delayed_notifications.detect { |e| e.resource.name == resource.name && e.action == :reload }).not_to be_nil
- run_context.resource_collection << Chef::Resource::ZenMaster.new("bean")
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("bean", run_context)
zrb = run_context.resource_collection.find(zen_master: "bean")
zrb.subscribes :reload, zr
expect(zr.delayed_notifications.detect { |e| e.resource.name == resource.name && e.action == :reload }).not_to be_nil
end
it "should make subscribed resources be capable of acting immediately" do
- run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
+ run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee", run_context)
zr = run_context.resource_collection.find(zen_master: "coffee")
resource.subscribes :reload, zr, :immediately
expect(zr.immediate_notifications.detect { |e| e.resource.name == resource.name && e.action == :reload }).not_to be_nil