summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavida Marion <davidamarion@gmail.com>2015-05-21 15:36:00 -0700
committerSerdar Sutay <serdar@opscode.com>2015-05-29 08:41:12 -0700
commit676342c040a2e282425648e6e833047c048fea7b (patch)
tree36957679f2f781b69a41bdb801d6f72aa6404188
parent3e1cbd6856eda733a1ed800184d8545e5d070e8e (diff)
downloadchef-676342c040a2e282425648e6e833047c048fea7b.tar.gz
adding unit tests
-rw-r--r--spec/support/shared/context/client.rb3
-rw-r--r--spec/unit/audit/logger_spec.rb20
2 files changed, 23 insertions, 0 deletions
diff --git a/spec/support/shared/context/client.rb b/spec/support/shared/context/client.rb
index e625185f7c..f5c21a3c65 100644
--- a/spec/support/shared/context/client.rb
+++ b/spec/support/shared/context/client.rb
@@ -201,6 +201,7 @@ shared_context "audit phase completed" do
def stub_for_audit
# -- Client#run_audits
expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
+ expect(Chef::Audit::Logger).to receive(:read_buffer).and_return("Audit mode output!")
expect(audit_runner).to receive(:run).and_return(true)
expect(client.events).to receive(:audit_phase_complete)
end
@@ -215,6 +216,7 @@ shared_context "audit phase failed with error" do
def stub_for_audit
expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
+ expect(Chef::Audit::Logger).to receive(:read_buffer).and_return("Audit mode output!")
expect(audit_runner).to receive(:run).and_raise(audit_error)
expect(client.events).to receive(:audit_phase_failed).with(audit_error)
end
@@ -232,6 +234,7 @@ shared_context "audit phase completed with failed controls" do
def stub_for_audit
expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
+ expect(Chef::Audit::Logger).to receive(:read_buffer).and_return("Audit mode output!")
expect(audit_runner).to receive(:run)
expect(Chef::Exceptions::AuditsFailed).to receive(:new).with(
audit_runner.num_failed, audit_runner.num_total
diff --git a/spec/unit/audit/logger_spec.rb b/spec/unit/audit/logger_spec.rb
index ae2cf9ef34..9dd9ce2cd9 100644
--- a/spec/unit/audit/logger_spec.rb
+++ b/spec/unit/audit/logger_spec.rb
@@ -19,4 +19,24 @@ require 'spec_helper'
describe Chef::Audit::Logger do
+ before(:each) do
+ Chef::Audit::Logger.instance_variable_set(:@buffer, nil)
+ end
+
+ it 'calling puts creates @buffer and adds the message' do
+ Chef::Audit::Logger.puts("Output message")
+ expect(Chef::Audit::Logger.read_buffer).to eq("Output message\n")
+ end
+
+ it 'calling puts multiple times adds to the message' do
+ Chef::Audit::Logger.puts("Output message")
+ Chef::Audit::Logger.puts("Output message")
+ Chef::Audit::Logger.puts("Output message")
+ expect(Chef::Audit::Logger.read_buffer).to eq("Output message\nOutput message\nOutput message\n")
+ end
+
+ it 'calling it before @buffer is set returns an empty string' do
+ expect(Chef::Audit::Logger.read_buffer).to eq("")
+ end
+
end