0

As part of a repeatable testing approach I'm looking to run a process and then compare its log file with an expected result. Here is a simplified example of the log file produced:


2020-09-01_01:00:00.000 INFO  : Incoming record count 123

2020-09-01_01:00:00.010 INFO  : Valid record count 120

I cannot use a static file to compare against using "diff" as the time stamps would change on each run (as would some other parts of the log contents). I'm thinking of using a file of regex's and using grep in a loop. A comparison file might look like:


^....-..-.._..:..:..\.... INFO  : Incoming record count [0-9]+$

^....-..-.._..:..:..\.... INFO  : Valid record count [0-9]+$

I would then use a loop to take a line at a time from the log file and the pattern file and compare the two using grep. Here is some pseudo-code for this:


while not eof

   read next line from log file

   read next line from pattern file

   grep pattern-line log-line

   if not matched then error and break loop

end

While functional this seems inefficient and inelegant so I'm looking for alternatives, or for comments that this actually a valid approach.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Jim Hudd
  • 47
  • 10
  • You could implode all regexes into one separated by `|`. Also, you regexes look to relaxed. It should be more like `^\d{4}-\d{2}-\d{2}_\d{2}:\d{2}:\d{2}\.\d{3} INFO : (Incoming|Valid) record count \d+$`. – Alexander Mashin Sep 22 '20 at 16:42
  • I simplified the regex's just for the example. I can't implode them to a single one because my log files have a number of lines - 2 in the example above - and the need to be those exact messages in that exact order. – Jim Hudd Sep 24 '20 at 17:02

0 Answers0