Sha256: f942fc12d5c068f4a64d1fba92d20eb7f8821ef47314cb3390af4af4d1f1a44b

Contents?: true

Size: 1.58 KB

Versions: 14

Compression:

Stored size: 1.58 KB

Contents

module ESHelper
  def self.get_host_port
    if ENV["INTEGRATION"] == "true"
      "elasticsearch:9200"
    else
      "localhost:9200"
    end
  end

  def self.curl_and_get_json_response(url, method: :get, args: nil); require 'open3'
    cmd = "curl -s -v --show-error #{args} -X #{method.to_s.upcase} -k #{url}"
    begin
      out, err, status = Open3.capture3(cmd)
    rescue Errno::ENOENT
      fail "curl not available, make sure curl binary is installed and available on $PATH"
    end

    if status.success?
      http_status = err.match(/< HTTP\/1.1 (.*?)/)[1] || '0' # < HTTP/1.1 200 OK\r\n
      if http_status.strip[0].to_i > 2
        warn out
        fail "#{cmd.inspect} unexpected response: #{http_status}\n\n#{err}"
      end

      LogStash::Json.load(out)
    else
      warn out
      fail "#{cmd.inspect} process failed: #{status}\n\n#{err}"
    end
  end

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

  def self.es_version
    ENV['ES_VERSION'] || ENV['ELASTIC_STACK_VERSION']
  end

  def self.es_version_satisfies?(*requirement)
    es_version = RSpec.configuration.filter[:es_version] || ENV['ES_VERSION'] || ENV['ELASTIC_STACK_VERSION']
    if es_version.nil?
      puts "Info: ES_VERSION, ELASTIC_STACK_VERSION 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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
logstash-filter-elasticsearch-3.17.0 spec/es_helper.rb
logstash-filter-elasticsearch-4.1.0 spec/es_helper.rb
logstash-filter-elasticsearch-4.0.0 spec/es_helper.rb
logstash-filter-elasticsearch-3.16.2 spec/es_helper.rb
logstash-filter-elasticsearch-3.16.1 spec/es_helper.rb
logstash-filter-elasticsearch-3.16.0 spec/es_helper.rb
logstash-filter-elasticsearch-3.15.3 spec/es_helper.rb
logstash-filter-elasticsearch-3.15.2 spec/es_helper.rb
logstash-filter-elasticsearch-3.15.1 spec/es_helper.rb
logstash-filter-elasticsearch-3.15.0 spec/es_helper.rb
logstash-filter-elasticsearch-3.14.0 spec/es_helper.rb
logstash-filter-elasticsearch-3.13.0 spec/es_helper.rb
logstash-filter-elasticsearch-3.12.0 spec/es_helper.rb
logstash-filter-elasticsearch-3.11.1 spec/es_helper.rb