diff options
author | jamesc <james@opscode.com> | 2013-10-11 16:24:48 -0700 |
---|---|---|
committer | jamesc <james@opscode.com> | 2013-10-15 14:53:09 -0700 |
commit | 62265ff2b7a75a6dc0135ae8105002a9803f01ce (patch) | |
tree | 7609785a1dead6a43b14cfa2ca678b3e4def0d66 /spec/unit/resource_reporter_spec.rb | |
parent | 6d58ff931dda2d5bfa0eb8b7feadf5cd0fb37c8e (diff) | |
download | chef-62265ff2b7a75a6dc0135ae8105002a9803f01ce.tar.gz |
When reporting a resource, before and after should always be a hash
If a Resource (or LWRP) overrides Resource#state (meaning to set an
attribute named state) this collides with the state function used to
gather up the state_attrs
Fix this by not using Resource#state, but copying that logic
into ResourceReporter#state.
Leaving Resource#state as it's used by other things. A full fix so
LWRPs can't override functions in Resource is in scope for Chef 12
Diffstat (limited to 'spec/unit/resource_reporter_spec.rb')
-rw-r--r-- | spec/unit/resource_reporter_spec.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index cb4f5bce94..e2ecde212f 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -464,6 +464,33 @@ describe Chef::ResourceReporter do end end + context "when including a resource that overrides Resource#state" do + before do + @current_state_resource = Chef::Resource::WithState.new("Stateful", @run_context) + @current_state_resource.state = nil + + @new_state_resource = Chef::Resource::WithState.new("Stateful", @run_context) + @new_state_resource.state = "Running" + @resource_reporter.resource_action_start(@new_state_resource, :create) + @resource_reporter.resource_current_state_loaded(@new_state_resource, :create, @current_state_resource) + @resource_reporter.resource_updated(@new_state_resource, :create) + @resource_reporter.resource_completed(@new_state_resource) + @run_status.stop_clock + @report = @resource_reporter.prepare_run_data + @first_update_report = @report["resources"].first + end + + it "sets before to {} instead of nil" do + @first_update_report.should have_key("before") + @first_update_report['before'].should eq({}) + end + + it "sets after to {} instead of 'Running'" do + @first_update_report.should have_key("after") + @first_update_report['after'].should eq({}) + end + end + end describe "when updating resource history on the server" do |