elasticsearch-test-runner 0.1.1 โ†’ 0.3.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: 259a2010d6c8c55a9f565bee24e7c50b3b2fea08714766797985b8eaa5db03fa
4
- data.tar.gz: 9d54c97d90b659a510589a3fd8513e9647d92492971f4d33db055f2b2fc95bde
3
+ metadata.gz: 736ee5a6506aad22d554ba00880706b6641192297e69c42a815050e4e6d784fd
4
+ data.tar.gz: 2faea7eacfc8c421675cbae4783fcce40866daf380a8d5fd417b297cd9de7e51
5
5
  SHA512:
6
- metadata.gz: 1b030edc69c376dd401c4f16f796fb35bd310754fa42bb509a0b8298d69de6d18a24bf1404e201b733c277f565daab98a4325758b95972fa453b60d8be03004e
7
- data.tar.gz: be60c13c2a9f49b2de32eb4cb1784bf2f6de6d14a049585ed4d8736fb4469ed81f2485b48744419789567ad5b9782303b625923318cc22a8542f0054c51972ba
6
+ metadata.gz: '0529c7247fe886df1ac6f99f95b45f2fd576dce42bcc80e01d032d57e3adda91f0556da62000201fa447fe7895b7799844c4479077f7136df382bcabb69f5ab8'
7
+ data.tar.gz: 90f5be281f003fb63ad11bb1180d47d5b3d50ab3db4914ff7652e2eb89cbfc828a78f2118ebf665e60e688f0e065011154b3bf7c4703b562d9f7a3f3256cc3e1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2024-06-27
4
+
5
+ - Fixes exit code.
6
+ - Refactors error handling for more detailed information.
7
+
8
+ ## [0.2.0] - 2024-06-25
9
+
10
+ - Renames gemspec from elasticsearch-tests to elasticsearch-test-runner.
11
+ - Adds ability to run individual test files or directories.
12
+
3
13
  ## [0.1.1] - 2024-06-20
4
14
 
5
15
  - Require 'fileutils' in Downloader.
data/README.md CHANGED
@@ -35,9 +35,30 @@ You can optionally pass in an object that implements Ruby's Logger to the `TestR
35
35
  logger = Logger.new($stdout)
36
36
  logger.level = Logger::WARN unless ENV['DEBUG']
37
37
 
38
- Elasticsearch::Tests::TestRunner.new(client, tests_path, logger).run
38
+ runner = Elasticsearch::Tests::TestRunner.new(client, tests_path, logger)
39
+ runner.run
39
40
  ```
40
41
 
42
+ When you run the tests, you can pass in the name of a particular test or a whole test folder, to run only those tests. Tests in the clients project are located [in the `tests` directory](https://github.com/elastic/elasticsearch-clients-tests/tree/main/tests) either as single yaml files or inside a specific directory, referring to a specific namespace. For example [`tests/get.yml`](https://github.com/elastic/elasticsearch-clients-tests/blob/main/tests/get.yml) and [`tests/bulk/10_basic.yml`](https://github.com/elastic/elasticsearch-clients-tests/blob/main/tests/bulk/10_basic.yml). If you want to run the `get.yml` test, you can pass in the file name to `run`:
43
+
44
+ ```ruby
45
+ runner.run('get.yml')
46
+ ```
47
+
48
+ If you want to run the basic bulk tests, you can run:
49
+
50
+ ```ruby
51
+ runner.run('bulk/10_basic.yml')
52
+ ```
53
+
54
+ If you want to run all the tests in a directory, you can pass in the directory:
55
+
56
+ ```ruby
57
+ runner.run('indices')
58
+ ```
59
+
60
+ This will run all the tests in [`tests/indices`](https://github.com/elastic/elasticsearch-clients-tests/tree/main/tests/indices) such as `alias.yml`, `analyze.yml`, and so on.
61
+
41
62
  You can **download the YAML test files** from [the clients tests project](https://github.com/elastic/elasticsearch-clients-tests) with the following code:
42
63
 
43
64
  ```ruby
@@ -19,5 +19,16 @@ module Elasticsearch
19
19
  module Tests
20
20
  class TestFailure < StandardError; end
21
21
  class TestError < StandardError; end
22
+
23
+ # Class to track exactly which action errored
24
+ class ActionError < StandardError
25
+ attr_reader :test_file, :action
26
+
27
+ def initialize(message, test_file, action)
28
+ super(message)
29
+ @test_file = test_file
30
+ @action = action
31
+ end
32
+ end
22
33
  end
23
34
  end
@@ -40,7 +40,7 @@ module Elasticsearch
40
40
  else
41
41
  pp response
42
42
  end
43
- raise Elasticsearch::Tests::TestFailure
43
+ raise Elasticsearch::Tests::ActionError.new('ERROR', @file, action)
44
44
  end
45
45
 
46
46
  def print_match_failure(action)
@@ -65,7 +65,9 @@ module Elasticsearch
65
65
  def self.display_errors(errors)
66
66
  puts "+++ โŒ Errors/Failures: #{errors.count}"
67
67
  errors.map do |error|
68
- puts "* Test: #{error[:file]}\n #{error[:error].message}"
68
+ puts "๐Ÿงช Test: #{error[:file]}"
69
+ puts "โ–ถ Action: #{error[:action]['do']}" if error[:action]
70
+ puts "๐Ÿ”ฌ #{error[:error].message}"
69
71
  pp error[:error].backtrace.join("$/\n") if ENV['DEBUG']
70
72
  puts
71
73
  end
@@ -16,6 +16,7 @@
16
16
  # under the License.
17
17
 
18
18
  require_relative 'code_runner'
19
+ require_relative 'errors'
19
20
 
20
21
  module Elasticsearch
21
22
  module Tests
@@ -70,6 +71,8 @@ module Elasticsearch
70
71
  when 'gt', 'gte', 'lt', 'lte'
71
72
  compare(action)
72
73
  end
74
+ rescue StandardError => e
75
+ raise ActionError.new(e.message, @file, action)
73
76
  end
74
77
 
75
78
  def run_setup
@@ -29,7 +29,7 @@ module Elasticsearch
29
29
 
30
30
  def initialize(client, path = nil, logger = nil)
31
31
  @client = client
32
- @serverless = (defined?(::ElasticsearchServerless) && client.is_a?(::ElasticsearchServerless::Client))
32
+ @serverless = defined?(::ElasticsearchServerless) && client.is_a?(::ElasticsearchServerless::Client)
33
33
  @path = path || File.expand_path('./tmp', __dir__)
34
34
  @logger = logger || LOGGER
35
35
  end
@@ -41,6 +41,11 @@ module Elasticsearch
41
41
  run_the_tests
42
42
  Elasticsearch::Tests::Printer::display_errors(@errors) unless @errors.empty?
43
43
  Elasticsearch::Tests::Printer::display_summary(@tests_count, @errors.count, @start_time)
44
+ if @errors.empty?
45
+ exit 0
46
+ else
47
+ exit 1
48
+ end
44
49
  end
45
50
 
46
51
  def run_the_tests
@@ -54,6 +59,9 @@ module Elasticsearch
54
59
  @errors << { error: e, file: test_file }
55
60
  @logger.warn("YAML error in #{test_file}")
56
61
  @logger.warn e
62
+ rescue ActionError => e
63
+ @errors << { error: e, file: test_file, action: e.action }
64
+ @logger.debug e
57
65
  rescue StandardError => e
58
66
  @errors << { error: e, file: test_file }
59
67
  @logger.debug e
@@ -74,13 +82,14 @@ module Elasticsearch
74
82
  end
75
83
 
76
84
  def select_test_files(test_files)
77
- if test_files.empty?
78
- Dir.glob("#{@path}/**/*.yml")
79
- else
80
- test_files.map do |test_file|
81
- "#{@path}/tests/#{test_file}"
82
- end
83
- end
85
+ tests_path = if test_files.empty?
86
+ "#{@path}/**/*.yml"
87
+ elsif test_files.include?('yml')
88
+ "#{@path}/#{test_files}"
89
+ else
90
+ "#{@path}/#{test_files}/*.yml"
91
+ end
92
+ Dir.glob(tests_path)
84
93
  end
85
94
 
86
95
  def extract_requires!(yaml)
@@ -19,6 +19,6 @@
19
19
 
20
20
  module Elasticsearch
21
21
  module Tests
22
- VERSION = "0.1.1"
22
+ VERSION = '0.3.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.1.1
4
+ version: 0.3.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-20 00:00:00.000000000 Z
11
+ date: 2024-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch
@@ -53,7 +53,6 @@ files:
53
53
  - NOTICE
54
54
  - README.md
55
55
  - Rakefile
56
- - elasticsearch-tests.gemspec
57
56
  - lib/elasticsearch/tasks/download_test_suite.rake
58
57
  - lib/elasticsearch/tests.rb
59
58
  - lib/elasticsearch/tests/code_runner.rb
@@ -1,51 +0,0 @@
1
- # Licensed to Elasticsearch B.V. under one or more contributor
2
- # license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright
4
- # ownership. Elasticsearch B.V. licenses this file to you under
5
- # the Apache License, Version 2.0 (the "License"); you may
6
- # not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing,
12
- # software distributed under the License is distributed on an
13
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- # KIND, either express or implied. See the License for the
15
- # specific language governing permissions and limitations
16
- # under the License.
17
-
18
- # frozen_string_literal: true
19
-
20
- require_relative 'lib/elasticsearch/tests/version'
21
-
22
- Gem::Specification.new do |spec|
23
- spec.name = 'elasticsearch-test-runner'
24
- spec.email = ['client-libs@elastic.co']
25
- spec.version = Elasticsearch::Tests::VERSION
26
- spec.authors = ['Elastic Client Library Maintainers']
27
- spec.licenses = ['Apache-2.0']
28
- spec.summary = 'Tool to test Elasticsearch clients against the YAML clients test suite.'
29
- spec.homepage = 'https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html'
30
- spec.description = 'A test runner for the Elasticsearch clients YAML test suite, used in the elasticsearch and elasticsearch-serverless gems.'
31
- spec.metadata['homepage_uri'] = spec.homepage
32
- spec.metadata['changelog_uri'] = 'https://github.com/elastic/es-test-runner-ruby/blob/main/CHANGELOG.md'
33
- spec.metadata['source_code_uri'] = 'https://github.com/elastic/es-test-runner-ruby/tree/main'
34
-
35
- spec.required_ruby_version = '>= 3.0'
36
-
37
- # Specify which files should be added to the gem when it is released.
38
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
39
- spec.files = Dir.chdir(__dir__) do
40
- `git ls-files -z`.split("\x0").reject do |f|
41
- (File.expand_path(f) == __FILE__) ||
42
- f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
43
- end
44
- end
45
- spec.bindir = 'exe'
46
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
47
- spec.require_paths = ['lib']
48
-
49
- spec.add_development_dependency 'elasticsearch'
50
- spec.add_development_dependency 'elasticsearch-serverless'
51
- end