Skip to content

Commit 72335d6

Browse files
committed
Adds YAML Test runner
1 parent b35794f commit 72335d6

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

elasticsearch-api/Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ source 'https://rubygems.org'
2020
# Specify your gem's dependencies in elasticsearch-api.gemspec
2121
gemspec
2222

23-
if File.exist? File.expand_path("../../elasticsearch/elasticsearch.gemspec", __FILE__)
24-
gem 'elasticsearch', path: File.expand_path('../../elasticsearch', __FILE__), require: false
23+
if File.exist? File.expand_path("../../elasticsearch/elasticsearch.gemspec", __dir__)
24+
gem 'elasticsearch', path: File.expand_path('../../elasticsearch', __dir__), require: false
2525
end
2626

2727
group :development do

elasticsearch-api/Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ namespace :test do
5050
Rake::Task['test:integration'].invoke
5151
end
5252

53+
desc 'Run tests with yaml runner'
54+
task :yaml do
55+
ruby './spec/yaml-test-runner/run.rb'
56+
end
57+
5358
namespace :platinum do
5459
desc 'Run Platinum Rest API Spec tests'
5560
RSpec::Core::RakeTask.new(:api) do

elasticsearch-api/elasticsearch-api.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Gem::Specification.new do |s|
4949
s.add_development_dependency 'ansi'
5050
s.add_development_dependency 'bundler'
5151
s.add_development_dependency 'elasticsearch'
52+
s.add_development_dependency 'elasticsearch-test-runner'
5253
s.add_development_dependency 'minitest'
5354
s.add_development_dependency 'minitest-reporters', '>= 1.6'
5455
s.add_development_dependency 'mocha'
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
require 'logger'
19+
require 'openssl'
20+
require 'elasticsearch'
21+
require 'elasticsearch/tests/test_runner'
22+
require 'elasticsearch/tests/downloader'
23+
24+
PROJECT_PATH = File.join(File.dirname(__FILE__), '../..')
25+
CERTS_PATH = "#{PROJECT_PATH}/../.buildkite/certs/".freeze
26+
host = ENV['TEST_ES_SERVER'] || 'https://localhost:9200'
27+
raise URI::InvalidURIError unless host =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
28+
29+
password = ENV['ELASTIC_PASSWORD'] || 'changeme'
30+
uri = URI.parse(host)
31+
32+
if uri.is_a?(URI::HTTPS)
33+
raw_certificate = File.read("#{CERTS_PATH}/testnode.crt")
34+
certificate = OpenSSL::X509::Certificate.new(raw_certificate)
35+
raw_key = File.read("#{CERTS_PATH}/testnode.key")
36+
key = OpenSSL::PKey::RSA.new(raw_key)
37+
ca_file = File.expand_path("#{CERTS_PATH}/ca.crt")
38+
host = "https://elastic:#{password}@#{uri.host}:#{uri.port}".freeze
39+
transport_options = {
40+
ssl: {
41+
client_cert: certificate,
42+
client_key: key,
43+
ca_file: ca_file,
44+
verify: false
45+
}
46+
}
47+
elsif uri.is_a?(URI::HTTP)
48+
host = "http://elastic:#{password}@#{uri.host}:#{uri.port}".freeze
49+
transport_options = {}
50+
end
51+
52+
if ENV['ES_API_KEY']
53+
CLIENT = Elasticsearch::Client.new(host: host, api_key: ENV['ES_API_KEY'], transport_options: transport_options)
54+
else
55+
CLIENT = Elasticsearch::Client.new(host: host, transport_options: transport_options)
56+
end
57+
58+
59+
tests_path = File.expand_path('./tmp', __dir__)
60+
61+
logger = Logger.new($stdout)
62+
logger.level = Logger::WARN unless ENV['DEBUG']
63+
64+
Elasticsearch::Tests::Downloader::run(tests_path)
65+
Elasticsearch::Tests::TestRunner.new(CLIENT, tests_path, logger).run

0 commit comments

Comments
 (0)