elasticsearch-test-runner 0.17.0 โ†’ 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce6c6e7adcbf6ba2d8f592f776d51bb1903b8ae2da6591981413fda1e44ce6e7
4
- data.tar.gz: e3d92c1626835a8c5eec26b85b1050c35b02e62c9f9e5e30abd64add7c0afe45
3
+ metadata.gz: 897b6c6fd42ff59d4a4a03ad00fd86ada140707095ded6dbdc16e24b1d1c7e57
4
+ data.tar.gz: 680d531cb3c7f06aa35b693c91d0b61f34e8a1aac5e5ba5fd89421b60a8589c8
5
5
  SHA512:
6
- metadata.gz: be441d1a5d468c450cd282f650134f4bd333d91b4c1bd373affb73c0f451283b0fe2a92f6e91cd9688e8b26e5e698edcd319b0c7c7759bb5ddb5e1ad3e0e1237
7
- data.tar.gz: 24850372db7b732513f58005e838044a8e637890b220fcd5a1f363beacff1bafe8747f5bf8af6c92ba9a388b85fabf815682b6ea025ff8acf9508b91a9a5e198
6
+ metadata.gz: 898b06aad5b5f1b4def588adccb9099e5618570884654650ab2704c471573b4fda55c3aa7fa3d4254cc9913c325f85d30b7160fecfe5e7f23fbff913370a972c
7
+ data.tar.gz: f8c9e058b5e78e69eac3ae80f3519572bd0166e4c1b3ddf785b3502e1cd8cff1824fd85d861254e195652dc399e8d7d116a80b3ca3de7cc06c5f1f3acf85b50e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.18.0] - 2026-03-05
4
+
5
+ - Lots of improvements when displaying errors. Fixes missing exceptions during particular failures. The display for errors and failures is now more detailed and comfortable to read.
6
+ - Fixes printing a success when there's no response object, for instance when catching an expected exception.
7
+ - The code for catching exceptions was refactored and made more reliable, including showing better information as previously mentioned.
8
+
3
9
  ## [0.17.0] - 2026-03-04
4
10
 
5
11
  - Better debugging detection, check for `ENV['DEBUG']` to be equal to `true`, not just if it's set.
@@ -60,11 +60,19 @@ module Elasticsearch
60
60
  print_debug_message(method.to_sym, params) if debug?
61
61
  @response
62
62
  rescue StandardError => e
63
- raise e unless expected_exception?(catchable, e)
64
-
65
- puts "Catchable: #{e}\nResponse: #{@response}\n" if debug?
63
+ # Raise if it's an actual error:
64
+ unless expected_exception?(catchable, e)
65
+ print_failure(action, @response)
66
+ raise e
67
+ end
68
+ # Show success if we caught an expected exception:
69
+ print_success
70
+ print_debug_catchable(e) if debug?
66
71
  end
67
72
 
73
+ # The keyword `catch` is used in the yaml tests to catch exceptions. This code looks at the
74
+ # expected error and the response error to compare them and check that we got the expected
75
+ # exception.
68
76
  def expected_exception?(error_type, e)
69
77
  return false if error_type.nil?
70
78
 
@@ -86,14 +94,14 @@ module Elasticsearch
86
94
  when 'forbidden'
87
95
  e.is_a?(Elastic::Transport::Transport::Errors::Forbidden)
88
96
  when /error parsing field/, /illegal_argument_exception/
89
- e.message =~ /\[400\]/ ||
97
+ e.message.match?(/\[400\]/) ||
90
98
  e.is_a?(Elastic::Transport::Transport::Errors::BadRequest)
91
99
  when /NullPointerException/
92
- e.message =~ /\[400\]/
100
+ e.message.match?(/\[400\]/)
93
101
  when /status_exception/
94
- e.message =~ /\[409\]/
102
+ e.message.match?(/\[409\]/)
95
103
  else
96
- e.message =~ /#{error_type}/
104
+ e.message.match?(/#{error_type}/)
97
105
  end
98
106
  end
99
107
 
@@ -112,6 +120,8 @@ module Elasticsearch
112
120
  print_success
113
121
  else
114
122
  print_match_failure(action)
123
+ message = "Match failure\nExpected #{k}: #{v}.\nResult: #{result}"
124
+ raise ActionError.new(message, $test_file, action)
115
125
  end
116
126
  end
117
127
 
@@ -129,6 +139,8 @@ module Elasticsearch
129
139
  print_success
130
140
  else
131
141
  print_failure(action, @response)
142
+ message = "do_length failure\nExpected #{k}: #{v}.\nResult: #{result}"
143
+ raise ActionError.new(message, $test_file, action)
132
144
  end
133
145
  end
134
146
 
@@ -147,6 +159,8 @@ module Elasticsearch
147
159
  print_success
148
160
  else
149
161
  print_failure(action, @response)
162
+ message = "is_true failure\nResponse: #{response_value || @response}."
163
+ raise ActionError.new(message, $test_file, action)
150
164
  end
151
165
  end
152
166
 
@@ -156,6 +170,8 @@ module Elasticsearch
156
170
  print_success
157
171
  else
158
172
  print_failure(action, @response)
173
+ message = "is_false failure\nResponse: #{response_value || @response}."
174
+ raise ActionError.new(message, $test_file, action)
159
175
  end
160
176
  end
161
177
 
@@ -166,11 +182,14 @@ module Elasticsearch
166
182
  #
167
183
  def compare(action)
168
184
  operator, value = action.first
185
+
169
186
  result = search_in_response(value.keys.first)
170
187
  if result&.send(COMPARATORS[operator], value[value.keys.first])
171
188
  print_success
172
189
  else
173
190
  print_failure(action, @response)
191
+ message = "comparision failure\n#{result} #{COMPARATORS[operator]} #{value[value.keys.first]}"
192
+ raise ActionError.new(message, $test_file, action)
174
193
  end
175
194
  end
176
195
 
@@ -30,8 +30,13 @@ module Elasticsearch
30
30
  if quiet?
31
31
  print '๐ŸŸข '
32
32
  else
33
- status = boolean_response? ? @response : @response.status
34
- puts "๐ŸŸข \e[33m#{@short_name}\e[0m - #{@action} \e[32mpassed\e[0m [#{status}]"
33
+ msg = "๐ŸŸข \e[33m#{@short_name}\e[0m - #{@action} \e[32mpassed\e[0m"
34
+ if @response.nil?
35
+ puts msg
36
+ else
37
+ status = boolean_response? ? @response : @response.status
38
+ puts "#{msg} [#{status}]"
39
+ end
35
40
  end
36
41
  end
37
42
 
@@ -46,23 +51,24 @@ module Elasticsearch
46
51
  puts "๐Ÿ”ด \e[33m#{@short_name}\e[0m - #{@action} \e[31mfailed\e[0m"
47
52
  end
48
53
  message = ["Expected result: #{action}"]
49
- if defined?(ElasticsearchServerless) &&
50
- response.is_a?(ElasticsearchServerless::API::Response) ||
51
- defined?(Elasticsearch::API) && response.is_a?(Elasticsearch::API::Response)
52
- message << 'Response:'
54
+ if response&.body
53
55
  message << response.body
54
56
  else
55
57
  message << response
56
58
  end
57
- raise Elasticsearch::Tests::ActionError.new(response.body, @short_name, action)
58
59
  end
59
60
 
60
61
  def print_match_failure(action)
61
62
  keys = action['match'].keys.first
62
63
  value = action['match'].values.first
63
64
 
65
+ if quiet?
66
+ print '๐Ÿ”ด '
67
+ else
68
+ puts "๐Ÿ”ด \e[33m#{@short_name} (match)\e[0m - \e[32;9m#{keys}: #{value}\e[0m \e[95m#{keys}: #{search_in_response(action['match'].keys.first)}\e[0m \e[31mfailed\e[0m"
69
+ end
64
70
  message = <<~MSG
65
- ๐Ÿ”ด #{@short_name} #{@title} failed
71
+ #{@short_name} #{@title} failed
66
72
  Expected: { #{keys}: #{value} }
67
73
  Actual : { #{keys}: #{search_in_response(action['match'].keys.first)} }
68
74
  Response: #{@response}
@@ -79,14 +85,16 @@ module Elasticsearch
79
85
  end
80
86
 
81
87
  def self.display_errors(errors, logger)
88
+ puts
82
89
  print TTY::Box.frame("โŒ Errors/Failures: #{errors.count}", width: BOX_WIDTH, style: { border: { fg: :red } })
83
- errors.map do |error|
90
+
91
+ errors.each do |error|
92
+ print TTY::Box.frame("๐Ÿงช Test: #{error[:file]}", width: BOX_WIDTH * 0.6, style: { border: { fg: :red } })
84
93
  message = []
85
- message << "๐Ÿงช Test: #{error[:file]}"
86
94
  message << "โ–ถ Action: #{error[:action].first}" if error[:action]
87
- message << "๐Ÿ”ฌ #{error.class} - #{error[:error].message}"
95
+ message << "๐Ÿ”ฌ #{error[:error].class} - #{error[:error].message}"
88
96
  message << error[:error].backtrace.join("$/\n") if ENV['DEBUG'] == 'true'
89
- print TTY::Box.frame(message.join("\n"), width: BOX_WIDTH, style: { border: { fg: :red } })
97
+ puts message.join("\n")
90
98
  logger.error(message.join("\n"))
91
99
  end
92
100
  end
@@ -99,6 +107,7 @@ module Elasticsearch
99
107
  #{summary}
100
108
  #{duration}
101
109
  MSG
110
+ puts
102
111
  print TTY::Box.frame(message, width: BOX_WIDTH, title: { top_left: '[SUMMARY]' }, style: { border: { fg: :cyan } })
103
112
  logger.info duration
104
113
  end
@@ -132,6 +141,14 @@ module Elasticsearch
132
141
  end
133
142
  end
134
143
 
144
+ def print_debug_catchable(exception)
145
+ puts TTY::Box.frame(
146
+ "Catchable: #{exception}\nResponse: #{@response}\n",
147
+ width: BOX_WIDTH,
148
+ title: { top_left: '[DEBUG]' }
149
+ )
150
+ end
151
+
135
152
  private
136
153
 
137
154
  def boolean_response?
@@ -86,8 +86,6 @@ module Elasticsearch
86
86
  test = Elasticsearch::Tests::Test.new(yaml, test_path, @client)
87
87
  test.execute
88
88
  @tests_count += test.count
89
- rescue StandardError => e
90
- raise e
91
89
  end
92
90
 
93
91
  def test_filename(file)
@@ -19,6 +19,6 @@
19
19
 
20
20
  module Elasticsearch
21
21
  module Tests
22
- VERSION = '0.17.0'
22
+ VERSION = '0.18.0'
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-test-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic Client Library Maintainers