diff options
author | danielsdeleo <dan@opscode.com> | 2012-12-21 11:29:29 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2012-12-27 09:37:44 -0700 |
commit | 1fbf3f48454ae47e13cdb502ad5d040865a9989a (patch) | |
tree | b9f0c608334605c3479c1de53de9939c329ab18c | |
parent | 76a1a65943fd80e9e05f37c0f7e19fe673819675 (diff) | |
download | chef-1fbf3f48454ae47e13cdb502ad5d040865a9989a.tar.gz |
[CHEF-3681] Test LWPs with inline compilation
-rw-r--r-- | spec/data/lwrp/providers/inline_compiler.rb | 26 | ||||
-rw-r--r-- | spec/unit/lwrp_spec.rb | 42 |
2 files changed, 68 insertions, 0 deletions
diff --git a/spec/data/lwrp/providers/inline_compiler.rb b/spec/data/lwrp/providers/inline_compiler.rb new file mode 100644 index 0000000000..2535276b24 --- /dev/null +++ b/spec/data/lwrp/providers/inline_compiler.rb @@ -0,0 +1,26 @@ + +use_inline_resources + +action :test do + + ruby_block "interior-ruby-block-1" do + block do + # doesn't need to do anything + end + notifies :run, "ruby_block[interior-ruby-block-2]", :immediately + end + + ruby_block "interior-ruby-block-2" do + block do + $interior_ruby_block_2 = "executed" + end + action :nothing + end +end + +action :no_updates do + ruby_block "no-action" do + block {} + action :nothing + end +end diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index b28fd812a2..a158bce440 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -226,6 +226,48 @@ describe "LWRP" do provider.enclosed_resource.monkey.should == 'bob, the monkey' end + describe "when using inline compilation" do + before do + # Behavior in these examples depends on implementation of fixture provider. + # See spec/data/lwrp/providers/inline_compiler + + # Side effect of lwrp_inline_compiler provider for testing notifications. + $interior_ruby_block_2 = nil + # resource type doesn't matter, so make an existing resource type work with provider. + @resource = Chef::Resource::LwrpFoo.new("morpheus", @run_context) + @resource.allowed_actions << :test + @resource.action(:test) + @resource.provider(:lwrp_inline_compiler) + end + + it "does not add interior resources to the exterior resource collection" do + @resource.run_action(:test) + @run_context.resource_collection.should be_empty + end + + context "when interior resources are updated" do + it "processes notifications within the LWRP provider's action" do + @resource.run_action(:test) + $interior_ruby_block_2.should == "executed" + end + + it "marks the parent resource updated" do + @resource.run_action(:test) + @resource.should be_updated + @resource.should be_updated_by_last_action + end + end + + context "when interior resources are not updated" do + it "does not mark the parent resource updated" do + @resource.run_action(:no_updates) + @resource.should_not be_updated + @resource.should_not be_updated_by_last_action + end + end + + end + end end |