Skip to content

Commit b36bb52

Browse files
author
Kevin Paulisse
committed
Bring in strip_log_message for better log analysis
1 parent 8347982 commit b36bb52

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

spec/octocatalog-diff/tests/spec_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ def self.setup_logger
217217
# remove the file and line locations. This takes the JSON result from catalog-diff and returns
218218
# a cleaned-up array of diffs.
219219
def self.remove_file_and_line(diff)
220+
if diff.is_a?(OctocatalogDiff::API::V1::Diff)
221+
result = diff.to_h.dup
222+
%w(new_location old_location new_line old_line new_file old_file).each { |x| result.delete(x.to_sym) }
223+
return result
224+
end
220225
if diff.is_a?(Hash)
221226
result = diff.dup
222227
%w(new_location old_location new_line old_line new_file old_file).each { |x| result.delete(x) }
@@ -228,6 +233,13 @@ def self.remove_file_and_line(diff)
228233
obj.map { |x| x[0] =~ /^[\-\+]$/ ? x[0..2] : x[0..3] }
229234
end
230235

236+
# Strip off timestamps and other extraneous content from log messages so that matching
237+
# of individual elements can be done via string and not regexp.
238+
def self.strip_log_message(message)
239+
return message unless message.strip =~ /\A\w,\s*\[[^\]]+\]\s+(\w+)\s*--\s*:(.+)/
240+
"#{Regexp.last_match(1)} - #{Regexp.last_match(2).strip}"
241+
end
242+
231243
# Get the Puppet version from the Puppet binary
232244
def self.puppet_version
233245
require require_path('util/puppetversion')

0 commit comments

Comments
 (0)