diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-03-16 11:57:44 -0700 |
---|---|---|
committer | Bryan McLellan <btm@chef.io> | 2015-03-17 09:10:04 -0400 |
commit | 625373d40febafa1c6621aaf179852601d303e6c (patch) | |
tree | 249ba5a901a71cd889764d1f58fac913d042217c /spec | |
parent | 576b45348fd975f1ded026ed45c6d83967e1a85c (diff) | |
download | chef-625373d40febafa1c6621aaf179852601d303e6c.tar.gz |
We should not change how exceptions are raised if audit mode is disabled
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/client_spec.rb | 91 |
1 files changed, 70 insertions, 21 deletions
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 2ec32b32ac..cf995838fa 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -24,6 +24,9 @@ require 'chef/run_context' require 'chef/rest' require 'rbconfig' +class FooError < RuntimeError +end + describe Chef::Client do let(:hostname) { "hostname" } @@ -428,34 +431,80 @@ describe Chef::Client do describe "when the audit phase fails" do context "with an exception" do - include_context "a client run" do - let(:e) { Exception.new } - def stub_for_audit - expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner) - expect(audit_runner).to receive(:run).and_raise(e) - expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(Chef::Exceptions::RunFailedWrappingError) + context "when audit mode is enabled" do + include_context "a client run" do + let(:e) { Exception.new } + def stub_for_audit + expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner) + expect(audit_runner).to receive(:run).and_raise(e) + expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(Chef::Exceptions::RunFailedWrappingError) + end + + def stub_for_run + expect_any_instance_of(Chef::RunLock).to receive(:acquire) + expect_any_instance_of(Chef::RunLock).to receive(:save_pid) + expect_any_instance_of(Chef::RunLock).to receive(:release) + + # Post conditions: check that node has been filled in correctly + expect(client).to receive(:run_started) + expect(client).to receive(:run_failed) + + expect_any_instance_of(Chef::ResourceReporter).to receive(:run_failed) + expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_failed) + end end - def stub_for_run - expect_any_instance_of(Chef::RunLock).to receive(:acquire) - expect_any_instance_of(Chef::RunLock).to receive(:save_pid) - expect_any_instance_of(Chef::RunLock).to receive(:release) - - # Post conditions: check that node has been filled in correctly - expect(client).to receive(:run_started) - expect(client).to receive(:run_failed) - - expect_any_instance_of(Chef::ResourceReporter).to receive(:run_failed) - expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_failed) + it "should save the node after converge and raise exception" do + expect{ client.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error| + expect(error.wrapped_errors.size).to eq(1) + expect(error.wrapped_errors[0]).to eq(e) + end end end - it "should save the node after converge and raise exception" do - expect{ client.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error| - expect(error.wrapped_errors.size).to eq(1) - expect(error.wrapped_errors[0]).to eq(e) + context "when audit mode is disabled" do + include_context "a client run" do + before do + Chef::Config[:audit_mode] = :disabled + end + + let(:e) { FooError.new } + + def stub_for_audit + expect(Chef::Audit::Runner).to_not receive(:new) + end + + def stub_for_converge + expect(Chef::Runner).to receive(:new).and_return(runner) + expect(runner).to receive(:converge).and_raise(e) + expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(FooError) + end + + def stub_for_node_save + expect(client).to_not receive(:save_updated_node) + end + + def stub_for_run + expect_any_instance_of(Chef::RunLock).to receive(:acquire) + expect_any_instance_of(Chef::RunLock).to receive(:save_pid) + expect_any_instance_of(Chef::RunLock).to receive(:release) + + + # Post conditions: check that node has been filled in correctly + expect(client).to receive(:run_started) + expect(client).to receive(:run_failed) + + expect_any_instance_of(Chef::ResourceReporter).to receive(:run_failed) + + end + + it "re-raises an unwrapped exception" do + expect { client.run }.to raise_error(FooError) + end end end + + end context "with failed audits" do |