summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-07-16 16:01:08 -0700
committerPete Higgins <pete@peterhiggins.org>2020-07-16 18:41:27 -0700
commit6c1b0b65afab4897e67fc21fae16a2e77a632eca (patch)
treea0bfbcb8b544ef7215ffd7281f19b975c94e4970 /spec/unit
parentb6d4990724237f58d0c6beb17eaf2268c894579e (diff)
downloadchef-6c1b0b65afab4897e67fc21fae16a2e77a632eca.tar.gz
Reset logger in test to avoid global state persisting.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/application_spec.rb1
-rw-r--r--spec/unit/log/syslog_spec.rb16
-rw-r--r--spec/unit/log/winevt_spec.rb34
-rw-r--r--spec/unit/provider/execute_spec.rb7
4 files changed, 27 insertions, 31 deletions
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index 031132f31d..4e77084644 100644
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -22,7 +22,6 @@ describe Chef::Application do
before do
@original_argv = ARGV.dup
ARGV.clear
- Chef::Log.logger = Logger.new(StringIO.new)
@app = Chef::Application.new
allow(@app).to receive(:trap)
allow(Dir).to receive(:chdir).and_return(0)
diff --git a/spec/unit/log/syslog_spec.rb b/spec/unit/log/syslog_spec.rb
index 004b00c3dc..1daacb89da 100644
--- a/spec/unit/log/syslog_spec.rb
+++ b/spec/unit/log/syslog_spec.rb
@@ -23,25 +23,21 @@ describe "Chef::Log::Syslog", unix_only: true do
before do
Chef::Log.init(MonoLogger.new(syslog))
- @old_log_level = Chef::Log.level
Chef::Log.level = :info
- @old_loggers = Chef::Log.loggers
- Chef::Log.use_log_devices([syslog])
- end
-
- after do
- Chef::Log.level = @old_log_level
- Chef::Log.use_log_devices(@old_loggers)
end
it "should send message with severity info to syslog." do
expect(syslog).to receive(:add).with(1, "*** Chef 12.4.0.dev.0 ***", nil)
- Chef::Log.info("*** Chef 12.4.0.dev.0 ***")
+ expect {
+ Chef::Log.info("*** Chef 12.4.0.dev.0 ***")
+ }.not_to output.to_stderr
end
it "should send message with severity warning to syslog." do
expect(syslog).to receive(:add).with(2, "No config file found or specified on command line. Using command line options instead.", nil)
- Chef::Log.warn("No config file found or specified on command line. Using command line options instead.")
+ expect {
+ Chef::Log.warn("No config file found or specified on command line. Using command line options instead.")
+ }.not_to output.to_stderr
end
it "should fallback into send message with severity info to syslog when wrong format." do
diff --git a/spec/unit/log/winevt_spec.rb b/spec/unit/log/winevt_spec.rb
index f3f8edc7ed..1130b77575 100644
--- a/spec/unit/log/winevt_spec.rb
+++ b/spec/unit/log/winevt_spec.rb
@@ -19,32 +19,40 @@
require "spec_helper"
-describe Chef::Log::WinEvt do
+describe Chef::Log::WinEvt, :windows_only do
let(:evtlog) { instance_double("Win32::EventLog") }
let(:winevt) { Chef::Log::WinEvt.new(evtlog) }
let(:app) { Chef::Application.new }
before do
Chef::Log.init(MonoLogger.new(winevt))
- @old_log_level = Chef::Log.level
Chef::Log.level = :info
- @old_loggers = Chef::Log.loggers
- Chef::Log.use_log_devices([winevt])
- end
-
- after do
- Chef::Log.level = @old_log_level
- Chef::Log.use_log_devices(@old_loggers)
end
it "should send message with severity info to Windows Event Log." do
- expect(winevt).to receive(:add).with(1, "*** Chef 12.4.0.dev.0 ***", nil)
- Chef::Log.info("*** Chef 12.4.0.dev.0 ***")
+ expect(evtlog).to receive(:report_event).with(
+ event_type: ::Win32::EventLog::INFO_TYPE,
+ source: Chef::Log::WinEvt::SOURCE,
+ event_id: Chef::Log::WinEvt::INFO_EVENT_ID,
+ data: ["*** Chef 12.4.0.dev.0 ***"]
+ )
+
+ expect {
+ Chef::Log.info("*** Chef 12.4.0.dev.0 ***")
+ }.not_to output.to_stderr
end
it "should send message with severity warning to Windows Event Log." do
- expect(winevt).to receive(:add).with(2, "No config file found or specified on command line. Using command line options instead.", nil)
- Chef::Log.warn("No config file found or specified on command line. Using command line options instead.")
+ expect(evtlog).to receive(:report_event).with(
+ event_type: ::Win32::EventLog::WARN_TYPE,
+ source: Chef::Log::WinEvt::SOURCE,
+ event_id: Chef::Log::WinEvt::WARN_EVENT_ID,
+ data: ["No config file found or specified on command line. Using command line options instead."]
+ )
+
+ expect {
+ Chef::Log.warn("No config file found or specified on command line. Using command line options instead.")
+ }.not_to output.to_stderr
end
it "should fallback into send message with severity info to Windows Event Log when wrong format." do
diff --git a/spec/unit/provider/execute_spec.rb b/spec/unit/provider/execute_spec.rb
index 80bdb6a230..e0c2243f26 100644
--- a/spec/unit/provider/execute_spec.rb
+++ b/spec/unit/provider/execute_spec.rb
@@ -43,17 +43,10 @@ describe Chef::Provider::Execute do
before do
allow(Chef::EventDispatch::EventsOutputStream).to receive(:new) { @live_stream }
allow(ChefUtils).to receive(:windows?) { false }
- @original_log_level = Chef::Log.level
Chef::Log.level = :info
allow(STDOUT).to receive(:tty?).and_return(false)
end
- after do
- Chef::Log.level = @original_log_level
- Chef::Config[:always_stream_execute] = false
- Chef::Config[:daemon] = false
- end
-
describe "#initialize" do
it "should return a Chef::Provider::Execute provider" do
expect(provider.class).to eql(Chef::Provider::Execute)