Sha256: ee8ee090517829f059b9c6258f630441e656cec5a485ca8020720f1041114ef2

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require "logstash/devutils/rspec/spec_helper"
require 'manticore'
require 'elasticsearch'

module ESHelper
  def get_host_port
    "127.0.0.1:9200"
  end

  def get_client
    Elasticsearch::Client.new(:hosts => [get_host_port])
  end

  def doc_type
    if ESHelper.es_version_satisfies?(">=7")
      "_doc"
    else
      "doc"
    end
  end

  def mapping_name
    if ESHelper.es_version_satisfies?(">=7")
      "_doc"
    else
      "_default_"
    end

  end

  def routing_field_name
    if ESHelper.es_version_satisfies?(">=6")
      :routing
    else
      :_routing
    end
  end

  def self.es_version
    RSpec.configuration.filter[:es_version] || ENV['ES_VERSION']
  end

  def self.es_version_satisfies?(*requirement)
    es_version = RSpec.configuration.filter[:es_version] || ENV['ES_VERSION']
    if es_version.nil?
      puts "Info: ES_VERSION environment or 'es_version' tag wasn't set. Returning false to all `es_version_satisfies?` call."
      return false
    end
    es_release_version = Gem::Version.new(es_version).release
    Gem::Requirement.new(requirement).satisfied_by?(es_release_version)
  end
end

RSpec.configure do |config|
  config.include ESHelper
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logstash-output-elasticsearch-9.2.4-java spec/es_spec_helper.rb