|
| 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