diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/support/lib/chef/resource/with_state.rb | 37 | ||||
-rw-r--r-- | spec/unit/resource_reporter_spec.rb | 27 |
2 files changed, 64 insertions, 0 deletions
diff --git a/spec/support/lib/chef/resource/with_state.rb b/spec/support/lib/chef/resource/with_state.rb new file mode 100644 index 0000000000..226de0a6d2 --- /dev/null +++ b/spec/support/lib/chef/resource/with_state.rb @@ -0,0 +1,37 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008, 2010 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'chef/knife' +require 'chef/json_compat' + +class Chef + class Resource + class WithState < Chef::Resource + attr_accessor :state + + def initialize(name, run_context=nil) + @resource_name = :with_state + super + end + + def state + @state + end + end + end +end 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 |