test/test_helper.rb in elasticsearch-api-6.8.3 vs test/test_helper.rb in elasticsearch-api-7.0.0.pre

- old
+ new

@@ -1,9 +1,31 @@ -# Licensed to Elasticsearch B.V under one or more agreements. -# Elasticsearch B.V licenses this file to you under the Apache 2.0 License. -# See the LICENSE file in the project root for more information +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS'] + hosts.split(',').map do |host| + /(http\:\/\/)?(\S+)/.match(host)[2] + end + end.freeze + +TEST_HOST, TEST_PORT = ELASTICSEARCH_HOSTS.first.split(':') if ELASTICSEARCH_HOSTS + + RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9' JRUBY = defined?(JRUBY_VERSION) if RUBY_1_8 and not ENV['BUNDLE_GEMFILE'] require 'rubygems' @@ -20,27 +42,77 @@ require 'simplecov-rcov' SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter SimpleCov.start { add_filter "/test|test_" } end -require 'test/unit' -require 'shoulda-context' -require 'mocha/setup' +require 'ansi' +require 'test/unit' if RUBY_1_8 +require 'minitest/autorun' +require 'minitest/reporters' +require 'shoulda/context' +require 'mocha/minitest' -unless ENV["NOTURN"] || RUBY_1_8 - require 'turn' +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new - if ENV['QUIET'] - Turn.config.format = :outline - Turn.config.trace = 1 - end -end - require 'require-prof' if ENV["REQUIRE_PROF"] require 'elasticsearch/api' RequireProf.print_timing_infos if ENV["REQUIRE_PROF"] if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9' require 'elasticsearch/extensions/test/cluster' require 'elasticsearch/extensions/test/startup_shutdown' require 'elasticsearch/extensions/test/profiling' unless JRUBY +end + +module Minitest + module Assertions + def assert_nothing_raised(*args) + begin + line = __LINE__ + yield + rescue RuntimeError => e + raise MiniTest::Assertion, "Exception raised:\n<#{e.class}>", e.backtrace + end + true + end + + def assert_not_nil(object, msg=nil) + msg = message(msg) { "<#{object.inspect}> expected to not be nil" } + assert !object.nil?, msg + end + + def assert_block(*msgs) + assert yield, *msgs + end + + alias :assert_raise :assert_raises + end +end + +module Elasticsearch + module Test + class UnitTest < ::Minitest::Test; end + + class FakeClient + include Elasticsearch::API + + def perform_request(method, path, params, body, headers={"Content-Type" => "application/json"}) + puts "PERFORMING REQUEST:", "--> #{method.to_s.upcase} #{path} #{params} #{body} #{headers}" + FakeResponse.new(200, 'FAKE', {}) + end + end + + FakeResponse = Struct.new(:status, :body, :headers) do + def status + values[0] || 200 + end + def body + values[1] || '{}' + end + def headers + values[2] || {} + end + end + + class NotFound < StandardError; end + end end