elasticsearch-test-runner 0.13.0 → 0.14.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: f62490fd713d82f5dd9206746d3a3dbfaf57cb0ffccd61ca5efadbdf3fb4dd8e
4
- data.tar.gz: e3ee9ccb983f74da0e1c55c49997812d332f49760c6af1d8ae33de3078aa8c78
3
+ metadata.gz: 3fdc3e700cee1701fdf46ac870a082c1f2e5442ec134861153a9a7810a228769
4
+ data.tar.gz: 261ad436f9db8d1d13b413df5967697ae1ac1f49a7886efcb97104c46fc07839
5
5
  SHA512:
6
- metadata.gz: 41ff67a4bf679214a2361e92a89873a68d972954b31d0abbafd982b34bf8b6f332ab37dec027960014cdf541c4462c42fa98095e9f22b85d9237eb10e3a72ac7
7
- data.tar.gz: 96dabaf5ea2445708b3cd834e6e9fa81e5a17b9df2e3c7d51e6da8594da6be4029e9ef9d8dd0200dd4297bb857df23ce2ac1d65c99533bf3a9218ae54aa43ea6
6
+ metadata.gz: 8629d1d7d526dd7eee04b6fa9496d3d64d63f0da9c374c92f16c74023ff02f9a7c3a106d11a7bdd95b16e058d8c65eceecec6ba2fcdc768078640cf49417af91
7
+ data.tar.gz: 7bb09a1d76a6d3bf382a4e67e3c39687c29ef0b7709e0edb5f5df4ded87c6f19e931952c031b7a4fb8478ca78742ded533cb341ef77f70d0c783fae5aa3527c2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.14.0] - 2026-01-29
4
+
5
+ - Introduces Ruby TTY tools for better debugging when `ENV['DEBUG']` is set and general display improvements.
6
+ - Better information for actions in passing/erroring tests, showing actions instead of the test title.
7
+
3
8
  ## [0.13.0] - 2025-06-05
4
9
 
5
10
  - Moves download tests file to Rakefile (namespace is unchanged).
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to Elasticsearch B.V. under one or more contributor
2
4
  # license agreements. See the NOTICE file distributed with
3
5
  # this work for additional information regarding copyright
@@ -53,15 +55,14 @@ module Elasticsearch
53
55
  client = @client.send(arrayed_method.first)
54
56
  method = arrayed_method.last
55
57
  end
56
- @response = client.send(method.to_sym, process_params(params))
57
- puts "Action: #{action}\nResponse: #{@response}\n\n" if ENV['DEBUG']
58
+ params = process_params(params)
59
+ @response = client.send(method.to_sym, params)
60
+ print_debug_message(method.to_sym, params) if ENV['DEBUG']
58
61
  @response
59
62
  rescue StandardError => e
60
- if expected_exception?(catchable, e)
61
- puts "Catchable: #{e}\nResponse: #{@response}\n" if ENV['DEBUG']
62
- else
63
- raise e
64
- end
63
+ raise e unless expected_exception?(catchable, e)
64
+
65
+ puts "Catchable: #{e}\nResponse: #{@response}\n" if ENV['DEBUG']
65
66
  end
66
67
 
67
68
  def expected_exception?(error_type, e)
@@ -116,13 +117,14 @@ module Elasticsearch
116
117
 
117
118
  def match_regexp(expected, result)
118
119
  expected.is_a?(String) &&
119
- expected.match?(/^\//) &&
120
+ expected.match?(%r{^/}) &&
120
121
  result.match?(Regexp.new(expected.gsub('/', '').strip))
121
122
  end
122
123
 
123
124
  def do_length(action)
124
125
  k, v = action['length'].first
125
- result = search_in_response(k).count
126
+ result = search_in_response(k)
127
+ result = result.count
126
128
  if result && result == v
127
129
  print_success
128
130
  else
@@ -208,11 +210,11 @@ module Elasticsearch
208
210
  end
209
211
 
210
212
  def set_param_variable(params, key, param)
211
- return unless param.is_a?(String) && param.include?("$")
213
+ return unless param.is_a?(String) && param.include?('$')
212
214
 
213
215
  # Param can be a single '$value' string or '{ something: $value }'
214
216
  repleacable = param.match(/(\$[0-9a-z_-]+)/)[0]
215
- value = instance_variable_get(repleacable.gsub("$", "@"))
217
+ value = instance_variable_get(repleacable.gsub('$', '@'))
216
218
  content = param.gsub(repleacable, value)
217
219
  params[key] = content
218
220
  end
@@ -14,6 +14,8 @@
14
14
  # KIND, either express or implied. See the License for the
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
+ require 'tty-box'
18
+ require 'tty-screen'
17
19
  require_relative 'errors'
18
20
 
19
21
  module Elasticsearch
@@ -22,29 +24,39 @@ module Elasticsearch
22
24
  # Functions to print out test results, errors, summary, etc.
23
25
  #
24
26
  module Printer
27
+ BOX_WIDTH = TTY::Screen.width * 0.8
28
+
25
29
  def print_success
26
30
  response = if [true, false].include? @response
27
31
  @response
28
32
  else
29
33
  @response.status
30
34
  end
31
- if ENV['QUIET'] == 'true'
35
+ if quiet?
32
36
  print '🟢 '
33
37
  else
34
- puts "🟢 #{@short_name} #{@title} passed. Response: #{response}"
38
+ puts "🟢 \e[#{33}m#{@short_name}\e[0m - #{@action} \e[#{32}mpassed\e[0m [#{response}]"
35
39
  end
36
40
  end
37
41
 
42
+ def quiet?
43
+ !ENV['QUIET'].nil? && ![false, 'false'].include?(ENV['QUIET'])
44
+ end
45
+
38
46
  def print_failure(action, response)
39
- puts "🔴 #{@short_name} #{@title} failed"
40
- puts "Expected result: #{action}" # TODO: Show match/length differently
47
+ if quiet?
48
+ print '🔴 '
49
+ else
50
+ puts "🔴 \e[#{33}m#{@short_name}\e[0m - #{@action} \e[#{31}mfailed\e[0m"
51
+ end
52
+ message = ["Expected result: #{action}"]
41
53
  if defined?(ElasticsearchServerless) &&
42
54
  response.is_a?(ElasticsearchServerless::API::Response) ||
43
55
  defined?(Elasticsearch::API) && response.is_a?(Elasticsearch::API::Response)
44
- puts 'Response:'
45
- pp response.body
56
+ message << 'Response:'
57
+ message << response.body
46
58
  else
47
- pp response
59
+ message << response
48
60
  end
49
61
  raise Elasticsearch::Tests::ActionError.new(response.body, @short_name, action)
50
62
  end
@@ -63,7 +75,7 @@ module Elasticsearch
63
75
  end
64
76
 
65
77
  def print_error(error)
66
- puts "❌ ERROR: #{@short_name} #{@title} failed\n"
78
+ print TTY::Box.error("❌ ERROR: #{@short_name} #{@title} failed", width: BOX_WIDTH)
67
79
  logger.error error.display
68
80
  backtrace = error.backtrace.join("\n")
69
81
  logger.error "#{backtrace}\n"
@@ -71,27 +83,40 @@ module Elasticsearch
71
83
  end
72
84
 
73
85
  def self.display_errors(errors, logger)
74
- puts "+++ ❌ Errors/Failures: #{errors.count}"
86
+ print TTY::Box.frame("❌ Errors/Failures: #{errors.count}", width: BOX_WIDTH, style: { border: { fg: :red } })
75
87
  errors.map do |error|
76
88
  message = []
77
89
  message << "🧪 Test: #{error[:file]}"
78
90
  message << "▶ Action: #{error[:action].first}" if error[:action]
79
91
  message << "🔬 #{error.class} - #{error[:error].message}"
80
92
  message << error[:error].backtrace.join("$/\n") if ENV['DEBUG']
81
- puts message.join("\n")
93
+ print TTY::Box.frame(message.join("\n"), width: BOX_WIDTH, style: { border: { fg: :red } })
82
94
  logger.error(message.join("\n"))
83
95
  end
84
96
  end
85
97
 
86
98
  def self.display_summary(tests_count, errors_count, start_time, logger)
87
- puts
88
99
  summary = "🧪 Tests: #{tests_count} | Passed: #{tests_count - errors_count} | Failed: #{errors_count}"
89
100
  logger.info summary
90
- puts "--- #{summary}"
91
-
92
101
  duration = "⏲ Elapsed time: #{Time.at(Time.now - start_time).utc.strftime('%H:%M:%S')}"
102
+ message = <<~MSG
103
+ #{summary}
104
+ #{duration}
105
+ MSG
106
+ print TTY::Box.frame(message, width: BOX_WIDTH, title: { top_left: '[SUMMARY]' }, style: { border: { fg: :cyan } })
93
107
  logger.info duration
94
- puts "--- #{duration}"
108
+ end
109
+
110
+ def print_debug_message(method, params)
111
+ message = <<~MSG
112
+ Test File: #{$test_file}
113
+ Action: #{method}
114
+ Parameters: #{params}
115
+ Response: #{@response.status}
116
+ Response headers: #{@response.headers}
117
+ Response body: #{@response.body}
118
+ MSG
119
+ print TTY::Box.frame(message, width: BOX_WIDTH, title: { top_left: '[DEBUG]'})
95
120
  end
96
121
  end
97
122
  end
@@ -59,18 +59,24 @@ module Elasticsearch
59
59
 
60
60
  case definition
61
61
  when 'do'
62
+ @action = "#{action['do'].keys.first}"
62
63
  do_action(action['do'])
63
64
  when 'set'
64
65
  set_variable(action)
65
66
  when 'match'
67
+ @action = "#{action.keys.first} #{format_action(action[action.keys.first])}"
66
68
  do_match(action)
67
69
  when 'length'
70
+ @action = format_action(action)
68
71
  do_length(action)
69
72
  when 'is_true'
73
+ @action = format_action(action)
70
74
  is_true(action)
71
75
  when 'is_false'
76
+ @action = format_action(action)
72
77
  is_false(action)
73
78
  when 'gt', 'gte', 'lt', 'lte'
79
+ @action = format_action(action)
74
80
  compare(action)
75
81
  end
76
82
  rescue StandardError => e
@@ -106,6 +112,17 @@ module Elasticsearch
106
112
  yaml.delete_at(i) if a.keys.first == 'teardown'
107
113
  end.compact.first
108
114
  end
115
+
116
+ private
117
+
118
+ def format_action(action)
119
+ action.to_s
120
+ .gsub(/^{/, '')
121
+ .gsub(' =>', ':')
122
+ .gsub('"', '')
123
+ .gsub('}', '')
124
+ .gsub('{', '|')
125
+ end
109
126
  end
110
127
  end
111
128
  end
@@ -64,17 +64,17 @@ module Elasticsearch
64
64
  @errors = []
65
65
 
66
66
  @test_files.map do |test_path|
67
- test_file = test_filename(test_path)
67
+ $test_file = test_filename(test_path)
68
68
  build_and_run_tests(test_path)
69
69
  rescue Psych::SyntaxError => e
70
- @errors << { error: e, file: test_file }
71
- @logger.warn("YAML error in #{test_file}")
70
+ @errors << { error: e, file: $test_file }
71
+ @logger.warn("YAML error in #{$test_file}")
72
72
  @logger.warn e
73
73
  rescue ActionError => e
74
- @errors << { error: e, file: test_file, action: e.action }
74
+ @errors << { error: e, file: $test_file, action: e.action }
75
75
  @logger.debug e
76
76
  rescue StandardError => e
77
- @errors << { error: e, file: test_file }
77
+ @errors << { error: e, file: $test_file }
78
78
  @logger.debug e
79
79
  rescue SystemExit, Interrupt
80
80
  exit
@@ -19,6 +19,6 @@
19
19
 
20
20
  module Elasticsearch
21
21
  module Tests
22
- VERSION = '0.13.0'
22
+ VERSION = '0.14.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.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic Client Library Maintainers
@@ -9,6 +9,34 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: tty-box
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: tty-screen
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
12
40
  - !ruby/object:Gem::Dependency
13
41
  name: elasticsearch
14
42
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
111
  requirements: []
84
- rubygems_version: 3.6.9
112
+ rubygems_version: 4.0.3
85
113
  specification_version: 4
86
114
  summary: Tool to test Elasticsearch clients against the YAML clients test suite.
87
115
  test_files: []