elasticsearch-test-runner 0.3.0 โ†’ 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 736ee5a6506aad22d554ba00880706b6641192297e69c42a815050e4e6d784fd
4
- data.tar.gz: 2faea7eacfc8c421675cbae4783fcce40866daf380a8d5fd417b297cd9de7e51
3
+ metadata.gz: fbe5745c193f66b9d4d16ca8402a9aba8d87068c43a328b565ac094e3dc679ae
4
+ data.tar.gz: b2fa5da01e5fa321c3b050dfd6cd08d1caf8f80fa5c5a903a5822e1dc88fb58a
5
5
  SHA512:
6
- metadata.gz: '0529c7247fe886df1ac6f99f95b45f2fd576dce42bcc80e01d032d57e3adda91f0556da62000201fa447fe7895b7799844c4479077f7136df382bcabb69f5ab8'
7
- data.tar.gz: 90f5be281f003fb63ad11bb1180d47d5b3d50ab3db4914ff7652e2eb89cbfc828a78f2118ebf665e60e688f0e065011154b3bf7c4703b562d9f7a3f3256cc3e1
6
+ metadata.gz: e153228ccd3fc6a7900c8744fef31c23e8b27ebda3bdbda682a4d1dca0ae720568144a30c90e199e417281d676bccaa45acdff6fd482b98039b20ab8b7ad9eb5
7
+ data.tar.gz: 4abc093012f30303cc8afaed96dea471cef8a6e4bd9ada4c7844ab35fe77f0593c9f850718c51f482068363d3998c715b5d9fc1e8fc4ab8905f478aafc88fc3b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2024-07-08
4
+
5
+ - Refactors display of errors/passing tests. Adds `QUIET` environment variable parsing. If `true`, display for passing tests will be more compact (not showing file/test names).
6
+ - Updates count for better accuracy in test results.
7
+ - Rescues SystemExit, Interrupt to actually exit the script
8
+ - Adds support for catch in tests: If the arguments to `do` include `catch`, then we are expecting an error, which should be caught and tested.
9
+
10
+ ## [0.3.1] - 2024-06-27
11
+
12
+ - Fixes in error handling.
13
+
3
14
  ## [0.3.0] - 2024-06-27
4
15
 
5
16
  - Fixes exit code.
@@ -35,6 +35,7 @@ module Elasticsearch
35
35
  # specifications. These are function calls to the Elasticsearch clients.
36
36
  #
37
37
  def do_action(action)
38
+ catchable = action.delete('catch')
38
39
  client = @client
39
40
  action = action.first if action.is_a?(Array)
40
41
  method, params = action.is_a?(String) ? [action, {}] : action.first
@@ -47,9 +48,40 @@ module Elasticsearch
47
48
  end
48
49
 
49
50
  @response = client.send(method.to_sym, process_params(params))
51
+ puts @response if ENV['DEBUG']
50
52
  @response
51
53
  rescue StandardError => e
52
- raise e
54
+ raise e unless expected_exception?(catchable, e)
55
+
56
+ @response
57
+ end
58
+
59
+ def expected_exception?(error_type, e)
60
+ case error_type
61
+ when 'request_timeout'
62
+ e.is_a?(Elastic::Transport::Transport::Errors::RequestTimeout)
63
+ when 'missing'
64
+ e.is_a?(Elastic::Transport::Transport::Errors::NotFound)
65
+ when 'conflict'
66
+ e.is_a?(Elastic::Transport::Transport::Errors::Conflict)
67
+ when 'request'
68
+ e.is_a?(Elastic::Transport::Transport::Errors::InternalServerError)
69
+ when 'bad_request'
70
+ e.is_a?(Elastic::Transport::Transport::Errors::BadRequest)
71
+ when 'param'
72
+ actual_error.is_a?(ArgumentError)
73
+ when 'unauthorized'
74
+ e.is_a?(Elastic::Transport::Transport::Errors::Unauthorized)
75
+ when 'forbidden'
76
+ e.is_a?(Elastic::Transport::Transport::Errors::Forbidden)
77
+ when /error parsing field/, /illegal_argument_exception/
78
+ e.message =~ /\[400\]/ ||
79
+ e.is_a?(Elastic::Transport::Transport::Errors::BadRequest)
80
+ when /NullPointerException/
81
+ e.message =~ /\[400\]/
82
+ else
83
+ e.message =~ /#{error_type}/
84
+ end
53
85
  end
54
86
 
55
87
  # Code for matching expectations and response
@@ -28,24 +28,31 @@ module Elasticsearch
28
28
  else
29
29
  @response.status
30
30
  end
31
- puts "๐ŸŸข #{@file} #{@title} passed. Response: #{response}"
31
+ if ENV['QUIET']
32
+ print "๐ŸŸข "
33
+ else
34
+ puts "๐ŸŸข #{@file} #{@title} passed. Response: #{response}"
35
+ end
32
36
  end
33
37
 
34
38
  def print_failure(action, response)
35
39
  puts "๐Ÿ”ด #{@file} #{@title} failed"
36
40
  puts "Expected result: #{action}" # TODO: Show match/length differently
37
- if response.is_a?(ElasticsearchServerless::API::Response)
41
+ if defined?(ElasticsearchServerless) &&
42
+ response.is_a?(ElasticsearchServerless::API::Response) ||
43
+ defined?(Elasticsearch::API) && response.is_a?(Elasticsearch::API::Response)
38
44
  puts 'Response:'
39
45
  pp response.body
40
46
  else
41
47
  pp response
42
48
  end
43
- raise Elasticsearch::Tests::ActionError.new('ERROR', @file, action)
49
+ raise Elasticsearch::Tests::ActionError.new(response.body, @file, action)
44
50
  end
45
51
 
46
52
  def print_match_failure(action)
47
53
  keys = action['match'].keys.first
48
54
  value = action['match'].values.first
55
+
49
56
  message = <<~MSG
50
57
  ๐Ÿ”ด #{@file} #{@title} failed
51
58
  Expected: { #{keys}: #{value} }
@@ -66,14 +73,15 @@ module Elasticsearch
66
73
  puts "+++ โŒ Errors/Failures: #{errors.count}"
67
74
  errors.map do |error|
68
75
  puts "๐Ÿงช Test: #{error[:file]}"
69
- puts "โ–ถ Action: #{error[:action]['do']}" if error[:action]
70
- puts "๐Ÿ”ฌ #{error[:error].message}"
76
+ puts "โ–ถ Action: #{error[:action].first}" if error[:action]
77
+ puts "๐Ÿ”ฌ #{error.class} - #{error[:error].message}"
71
78
  pp error[:error].backtrace.join("$/\n") if ENV['DEBUG']
72
79
  puts
73
80
  end
74
81
  end
75
82
 
76
83
  def self.display_summary(tests_count, errors_count, start_time)
84
+ puts
77
85
  puts "--- ๐Ÿงช Tests: #{tests_count} | Passed: #{tests_count - errors_count} | Failed: #{errors_count}"
78
86
  puts "--- โฒ Elapsed time: #{Time.at(Time.now - start_time).utc.strftime("%H:%M:%S")}"
79
87
  end
@@ -90,7 +90,7 @@ module Elasticsearch
90
90
  end
91
91
 
92
92
  def count
93
- @actions.length
93
+ @actions.select { |a| a.keys.first == 'do' }.count
94
94
  end
95
95
 
96
96
  def test_filename(file)
@@ -65,6 +65,8 @@ module Elasticsearch
65
65
  rescue StandardError => e
66
66
  @errors << { error: e, file: test_file }
67
67
  @logger.debug e
68
+ rescue SystemExit, Interrupt
69
+ exit
68
70
  end
69
71
  end
70
72
 
@@ -19,6 +19,6 @@
19
19
 
20
20
  module Elasticsearch
21
21
  module Tests
22
- VERSION = '0.3.0'
22
+ VERSION = '0.4.0'
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-test-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic Client Library Maintainers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-27 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch