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

Instance Method Summary collapse

Class Method Details

.display_errors(errors) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/elasticsearch/tests/printer.rb', line 73

def self.display_errors(errors)
  puts "+++ โŒ Errors/Failures: #{errors.count}"
  errors.map do |error|
    puts "๐Ÿงช Test: #{error[:file]}"
    puts "โ–ถ Action: #{error[:action].first}" if error[:action]
    puts "๐Ÿ”ฌ #{error.class} - #{error[:error].message}"
    pp error[:error].backtrace.join("$/\n") if ENV['DEBUG']
    puts
  end
end

.display_summary(tests_count, errors_count, start_time) ⇒ Object



84
85
86
87
88
# File 'lib/elasticsearch/tests/printer.rb', line 84

def self.display_summary(tests_count, errors_count, start_time)
  puts
  puts "--- ๐Ÿงช Tests: #{tests_count} | Passed: #{tests_count - errors_count} | Failed: #{errors_count}"
  puts "--- โฒ  Elapsed time: #{Time.at(Time.now - start_time).utc.strftime("%H:%M:%S")}"
end

Instance Method Details



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


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


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

  message = <<~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(message)
end


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