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.