summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2014-10-15 08:30:33 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2014-10-22 13:03:22 -0700
commit1cf4fbcc48da1a92b0aaa34ea7dec5ec04e44fa9 (patch)
tree683769873f39d3a57d17f6490f1d9b47beee497e
parent68e9da3ab941c2a9c73618ac2dfc79c1ff98f290 (diff)
downloadchef-1cf4fbcc48da1a92b0aaa34ea7dec5ec04e44fa9.tar.gz
Added spec for windows event logger
-rw-r--r--spec/functional/logging/windows_eventlog_spec.rb76
1 files changed, 76 insertions, 0 deletions
diff --git a/spec/functional/logging/windows_eventlog_spec.rb b/spec/functional/logging/windows_eventlog_spec.rb
new file mode 100644
index 0000000000..9958a61c02
--- /dev/null
+++ b/spec/functional/logging/windows_eventlog_spec.rb
@@ -0,0 +1,76 @@
+#
+# Author:: Adam Edwards (<adamed@getchef.com>)
+#
+# Copyright:: 2014, Chef Software, Inc.
+#
+# 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 'spec_helper'
+require 'securerandom'
+require 'chef/logging/windows_eventlog'
+require 'win32/eventlog'
+include Win32
+
+describe Chef::Logging::WindowsEventLogger, :windows_only do
+ let(:run_id) { SecureRandom.uuid }
+ let(:version) { SecureRandom.uuid }
+ let(:elapsed_time) { SecureRandom.random_number(100) }
+ let(:logger) { Chef::Logging::WindowsEventLogger.new }
+ let(:flags) { nil }
+ let(:node) { nil }
+ let(:run_status) { double('Run Status', {run_id: run_id, elapsed_time: elapsed_time }) }
+ let(:event_log) { EventLog.new("Application") }
+ let!(:offset) { event_log.read_last_event.record_number }
+ let(:mock_exception) { double('Exception', {message: SecureRandom.uuid, backtrace:[SecureRandom.uuid, SecureRandom.uuid]})}
+
+ it 'writes run_start event with event_id 10000 and contains version' do
+ logger.run_start(version)
+
+ expect(event_log.read(flags, offset).any? { |e| e.source == 'Chef' && e.event_id == 10000 &&
+ e.string_inserts[0].include?(version)}).to be_true
+ end
+
+ it 'writes run_started event with event_id 10001 and contains the run_id' do
+ logger.run_started(run_status)
+
+ expect(event_log.read(flags, offset).any? { |e| e.source == 'Chef' && e.event_id == 10001 &&
+ e.string_inserts[0].include?(run_id)}).to be_true
+ end
+
+ it 'writes run_completed event with event_id 10002 and contains the run_id and elapsed time' do
+ logger.run_started(run_status)
+ logger.run_completed(node)
+
+ expect(event_log.read(flags, offset).any? { |e| e.source == 'Chef' && e.event_id == 10002 &&
+ e.string_inserts[0].include?(run_id) &&
+ e.string_inserts[1].include?(elapsed_time.to_s)
+ }).to be_true
+ end
+
+ it 'writes run_failed event with event_id 10003 and contains the run_id, elapsed time, and exception info' do
+ logger.run_started(run_status)
+ logger.run_failed(mock_exception)
+
+ expect(event_log.read(flags, offset).any? do |e|
+ e.source == 'Chef' && e.event_id == 10003 &&
+ e.string_inserts[0].include?(run_id) &&
+ e.string_inserts[1].include?(elapsed_time.to_s) &&
+ e.string_inserts[2].include?(mock_exception.class.name) &&
+ e.string_inserts[3].include?(mock_exception.message) &&
+ e.string_inserts[4].include?(mock_exception.backtrace[0]) &&
+ e.string_inserts[4].include?(mock_exception.backtrace[1])
+ end).to be_true
+ end
+
+end