Module: Elasticsearch::Tests::Printer
- Included in:
- CodeRunner
- Defined in:
- lib/elasticsearch/tests/printer.rb
Overview
Functions to print out test results, errors, summary, etc.
Class Method Summary collapse
- .display_errors(errors, logger) ⇒ Object
- .display_summary(tests_count, errors_count, start_time, logger) ⇒ Object
Instance Method Summary collapse
- #print_error(error) ⇒ Object
- #print_failure(action, response) ⇒ Object
- #print_match_failure(action) ⇒ Object
- #print_success ⇒ Object
Class Method Details
.display_errors(errors, logger) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/elasticsearch/tests/printer.rb', line 73 def self.display_errors(errors, logger) puts "+++ โ Errors/Failures: #{errors.count}" errors.map do |error| = [] << "๐งช Test: #{error[:file]}" << "โถ Action: #{error[:action].first}" if error[:action] << "๐ฌ #{error.class} - #{error[:error].}" << error[:error].backtrace.join("$/\n") if ENV['DEBUG'] puts .join("\n") logger.error(.join("\n")) end end |
.display_summary(tests_count, errors_count, start_time, logger) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/elasticsearch/tests/printer.rb', line 86 def self.display_summary(tests_count, errors_count, start_time, logger) puts summary = "๐งช Tests: #{tests_count} | Passed: #{tests_count - errors_count} | Failed: #{errors_count}" logger.info summary puts "--- #{summary}" duration = "โฒ Elapsed time: #{Time.at(Time.now - start_time).utc.strftime('%H:%M:%S')}" logger.info duration puts "--- #{duration}" end |
Instance Method Details
#print_error(error) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/elasticsearch/tests/printer.rb', line 65 def print_error(error) puts "โ ERROR: #{@short_name} #{@title} failed\n" logger.error error.display backtrace = error.backtrace.join("\n") logger.error "#{backtrace}\n" raise error end |
#print_failure(action, response) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elasticsearch/tests/printer.rb', line 38 def print_failure(action, response) puts "๐ด #{@short_name} #{@title} failed" puts "Expected result: #{action}" # TODO: Show match/length differently if defined?(ElasticsearchServerless) && response.is_a?(ElasticsearchServerless::API::Response) || defined?(Elasticsearch::API) && response.is_a?(Elasticsearch::API::Response) puts 'Response:' pp response.body else pp response end raise Elasticsearch::Tests::ActionError.new(response.body, @short_name, action) end |
#print_match_failure(action) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/elasticsearch/tests/printer.rb', line 52 def print_match_failure(action) keys = action['match'].keys.first value = action['match'].values.first = <<~MSG ๐ด #{@short_name} #{@title} failed Expected: { #{keys}: #{value} } Actual : { #{keys}: #{search_in_response(action['match'].keys.first)} } Response: #{@response} MSG raise Elasticsearch::Tests::TestFailure.new() end |
#print_success ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/elasticsearch/tests/printer.rb', line 25 def print_success response = if [true, false].include? @response @response else @response.status end if ENV['QUIET'] == 'true' print '๐ข ' else puts "๐ข #{@short_name} #{@title} passed. Response: #{response}" end end |