elasticsearch-test-runner 0.6.0 → 0.8.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: ee56a5237bb5f84f1736eadf3d0bc16368cccd7889bbaf2a5a9f39f4c252e821
4
- data.tar.gz: 102d52581d5663b0848d3b2a794b12c20bc11f195a79f2cb8ac57c94e1b818c5
3
+ metadata.gz: d09d996ce00f24cbdd34e54d447eff53c19a0a023fa55a61043a5215626e21a8
4
+ data.tar.gz: 77fc59d5846f32c165dcb3ac72bf475c0e572a12f03e7aab80a85030b6e6d7c0
5
5
  SHA512:
6
- metadata.gz: c0bdd05bd218933af4dc65c51917829bc68f07e312c959fbce1b0efbf6446444af48fd1ae72620a98cd9ce8836a5454807a988f007de0ccd7201a13f3868de9e
7
- data.tar.gz: 1cfb660fe7e81c143e42e6aaf886b4f2b3d5f33dbee48a78234f27518725bfacf52af1ca5a27d6f65521de9a8139e18fbe6926c6fdc93c13fb54eaebd182009a
6
+ metadata.gz: 69587a3c06c098c03c74e2b26f114228012ee97d73267a5623e44e0d689e776d0c9dc85a1cc503a0ac397c68d9939c338bd6a88bcaf0ffacf2cbf77a31d0cc17
7
+ data.tar.gz: 4b4e6315e953fbc534b8fdbc06db5462e7656cee80c1f5edfbd21cbede0956513e2f7d45faff87c77b5cf61a34526d89d9a9b907d4887ff8e9d4cbf4258b6b1b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.0] - 2024-08-14
4
+
5
+ - Adds support for variable keys (`$`).
6
+
7
+ ## [0.7.0] - 2024-08-08
8
+
9
+ - Improves test (file) name display
10
+ - Updates QUIET environment variable check
11
+
3
12
  ## [0.6.0] - 2024-08-07
4
13
 
5
14
  - Adds `header` support, headers can be specified for an action.
@@ -176,13 +176,11 @@ module Elasticsearch
176
176
  # Given a key coming from a test definition, search the response body for a matching value.
177
177
  #
178
178
  def search_in_response(keys)
179
- if (match = /\$([a-z]+)/.match(keys))
180
- return @response.send(match[1])
181
- end
182
-
183
179
  if keys.include?('.')
184
180
  key = split_and_parse_key(keys)
185
181
  return find_value_in_document(key, @response.body)
182
+ elsif (match = /\$([a-z]+)/.match(keys))
183
+ return @response.send(match[1])
186
184
  end
187
185
 
188
186
  @response[keys]
@@ -217,7 +215,9 @@ module Elasticsearch
217
215
  return document[chain[0]] unless chain.size > 1
218
216
 
219
217
  # a number can be a string key in a Hash or indicate an element in a list
220
- if document.is_a?(Hash)
218
+ if chain[0].is_a?(String) && chain[0].match?(/^\$/)
219
+ find_value_in_document(chain[1..], instance_variable_get("@#{chain[0].gsub('$', '')}"))
220
+ elsif document.is_a?(Hash)
221
221
  find_value_in_document(chain[1..], document[chain[0].to_s]) if document[chain[0].to_s]
222
222
  elsif document[chain[0]]
223
223
  find_value_in_document(chain[1..], document[chain[0]]) if document[chain[0]]
@@ -28,15 +28,15 @@ module Elasticsearch
28
28
  else
29
29
  @response.status
30
30
  end
31
- if ENV['QUIET']
31
+ if ENV['QUIET'] == 'true'
32
32
  print '🟢 '
33
33
  else
34
- puts "🟢 #{@file} #{@title} passed. Response: #{response}"
34
+ puts "🟢 #{@short_name} #{@title} passed. Response: #{response}"
35
35
  end
36
36
  end
37
37
 
38
38
  def print_failure(action, response)
39
- puts "🔴 #{@file} #{@title} failed"
39
+ puts "🔴 #{@short_name} #{@title} failed"
40
40
  puts "Expected result: #{action}" # TODO: Show match/length differently
41
41
  if defined?(ElasticsearchServerless) &&
42
42
  response.is_a?(ElasticsearchServerless::API::Response) ||
@@ -46,7 +46,7 @@ module Elasticsearch
46
46
  else
47
47
  pp response
48
48
  end
49
- raise Elasticsearch::Tests::ActionError.new(response.body, @file, action)
49
+ raise Elasticsearch::Tests::ActionError.new(response.body, @short_name, action)
50
50
  end
51
51
 
52
52
  def print_match_failure(action)
@@ -54,7 +54,7 @@ module Elasticsearch
54
54
  value = action['match'].values.first
55
55
 
56
56
  message = <<~MSG
57
- 🔴 #{@file} #{@title} failed
57
+ 🔴 #{@short_name} #{@title} failed
58
58
  Expected: { #{keys}: #{value} }
59
59
  Actual : { #{keys}: #{search_in_response(action['match'].keys.first)} }
60
60
  Response: #{@response}
@@ -63,7 +63,7 @@ module Elasticsearch
63
63
  end
64
64
 
65
65
  def print_error(error)
66
- puts "❌ ERROR: #{@file} #{@title} failed\n"
66
+ puts "❌ ERROR: #{@short_name} #{@title} failed\n"
67
67
  logger.error error.display
68
68
  backtrace = error.backtrace.join("\n")
69
69
  logger.error "#{backtrace}\n"
@@ -33,7 +33,9 @@ module Elasticsearch
33
33
  @teardown = extract_teardown!(yaml)
34
34
  @title = yaml.first.keys.first
35
35
  @actions = yaml.first[@title]
36
- @file = test_filename(file)
36
+ @file = file
37
+ name = file.split('/')
38
+ @short_name = "#{name[-2]}/#{name[-1]}"
37
39
  @client = client
38
40
  end
39
41
 
@@ -93,11 +95,6 @@ module Elasticsearch
93
95
  @actions.select { |a| a.keys.first == 'do' }.count
94
96
  end
95
97
 
96
- def test_filename(file)
97
- name = file.split('/')
98
- "#{name[-2]}/#{name[-1]}"
99
- end
100
-
101
98
  def extract_setup!(yaml)
102
99
  yaml.map.with_index do |a, i|
103
100
  yaml.delete_at(i) if a.keys.first == 'setup'
@@ -53,8 +53,9 @@ module Elasticsearch
53
53
  @tests_count = 0
54
54
  @errors = []
55
55
 
56
- @test_files.map do |test_file|
57
- build_and_run_tests(test_file)
56
+ @test_files.map do |test_path|
57
+ test_file = test_filename(test_path)
58
+ build_and_run_tests(test_path)
58
59
  rescue Psych::SyntaxError => e
59
60
  @errors << { error: e, file: test_file }
60
61
  @logger.warn("YAML error in #{test_file}")
@@ -70,19 +71,24 @@ module Elasticsearch
70
71
  end
71
72
  end
72
73
 
73
- def build_and_run_tests(test_file)
74
- yaml = YAML.load_stream(File.read(test_file))
74
+ def build_and_run_tests(test_path)
75
+ yaml = YAML.load_stream(File.read(test_path))
75
76
  requires = extract_requires!(yaml).compact.first['requires']
76
77
  return unless (requires['serverless'] == true && @serverless) ||
77
78
  (requires['stack'] == true && !@serverless)
78
79
 
79
- test = Elasticsearch::Tests::Test.new(yaml, test_file, @client)
80
+ test = Elasticsearch::Tests::Test.new(yaml, test_path, @client)
80
81
  test.execute
81
82
  @tests_count += test.count
82
83
  rescue StandardError => e
83
84
  raise e
84
85
  end
85
86
 
87
+ def test_filename(file)
88
+ name = file.split('/')
89
+ "#{name[-2]}/#{name[-1]}"
90
+ end
91
+
86
92
  def select_test_files(test_files)
87
93
  tests_path = if test_files.empty?
88
94
  "#{@path}/**/*.yml"
@@ -19,6 +19,6 @@
19
19
 
20
20
  module Elasticsearch
21
21
  module Tests
22
- VERSION = '0.6.0'
22
+ VERSION = '0.8.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.6.0
4
+ version: 0.8.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-08-07 00:00:00.000000000 Z
11
+ date: 2024-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch