From cadb07d62f19e0da476599d8a729cf7c877ee848 Mon Sep 17 00:00:00 2001 From: halilsen Date: Fri, 10 Dec 2021 12:03:29 +0100 Subject: [PATCH] Improve log pattern test --- test/api/v01/vrp_test.rb | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/test/api/v01/vrp_test.rb b/test/api/v01/vrp_test.rb index 105765092..f143da5d9 100644 --- a/test/api/v01/vrp_test.rb +++ b/test/api/v01/vrp_test.rb @@ -286,6 +286,8 @@ def test_block_call_under_clustering end def test_unfounded_avancement_message_change + todays = [Date.today] + times = [Time.now] lines_with_avancement = '' Dir.mktmpdir('temp_', 'test/') { |tmpdir| begin @@ -314,26 +316,34 @@ def test_unfounded_avancement_message_change output&.unlink end } + todays << Date.today + times << Time.now assert_msg = "\nThe structure of avancement message has changed! If the modification is on purpose " \ "fix this test \n(#{self.class.name}::#{self.name}) to represent the actual functionality." # Currently the expected output is in the following form - # [date time] jobid - INFO: avancement: repetition (1..2)/2 - clustering phase (y: 1..2)/2 - step (1..y)/(y) - # [date time] jobid - INFO: avancement: repetition (1..2)/2 - process (1..9)/10 - solving periodic heuristic + # [date time_with_ms_and_zone] jobid - INFO: avancement: repetition (1..2)/2 - clustering phase (y: 1..2)/2 - step (1..y)/(y) + # [date time_with_ms_and_zone] jobid - INFO: avancement: repetition (1..2)/2 - process (1..9)/10 - solving periodic heuristic lines_with_avancement.each{ |line| - date_time_jobid = '\[(?[0-9-]*) (?[0-9:. +]*)\] (?[0-9a-z]*)' + date_time_jobid_pattern = '\[(?[0-9-]*) (?[0-9:. +]*)\] (?[0-9a-z]*)' # There needs to be avancement and repetition - %r{#{date_time_jobid} - INFO: avancement: repetition [1-2]/2 - (?.*)\n} =~ line + %r{#{date_time_jobid_pattern} - INFO: avancement: repetition [1-2]/2 - (?.*)\n} =~ line refute_nil Regexp.last_match, assert_msg - refute_nil Regexp.last_match(:date)&.to_date, assert_msg - refute_nil Regexp.last_match(:hour)&.to_time, assert_msg + matched_date = Regexp.last_match(:date)&.to_date + refute_nil matched_date, assert_msg + assert_includes todays, matched_date, assert_msg - rest = Regexp.last_match(:rest) + matched_time = Regexp.last_match(:time_with_ms_and_zone)&.to_time + refute_nil matched_time, assert_msg + assert_operator matched_time, :>=, times.first, assert_msg + assert_operator matched_time, :<=, times.last, assert_msg - # The rest needs to be either clustering or heuristic solution - %r{clustering phase [1-2]/2 - step [1-2]/[1-2] } =~ rest || %r{process [1-9]/8 - periodic heuristic } =~ rest + remaining_log = Regexp.last_match(:remaining_log) + + # The remaining_log needs to be either clustering or heuristic solution + %r{clustering phase [1-2]/2 - step [1-2]/[1-2] } =~ remaining_log || %r{process [1-9]/8 - periodic heuristic } =~ remaining_log refute_nil Regexp.last_match, assert_msg }