Sha256: 8afc6d6bb493e0244ab6e2a6f738cd4e977ce2cd12878370c4105fd98b2ba9e5

Contents?: true

Size: 1.84 KB

Versions: 11

Compression:

Stored size: 1.84 KB

Contents

require "logstash/devutils/rspec/spec_helper"
require "ftw"
require "logstash/plugin"
require "logstash/json"
require "stud/try"
require "longshoreman"

CONTAINER_NAME = "logstash-output-elasticsearch-#{rand(999).to_s}"
CONTAINER_IMAGE = "elasticsearch"
CONTAINER_TAG = "1.6"

module ESHelper

  def get_host
    Longshoreman.new.get_host_ip
  end

  def get_port(protocol)
    container = Longshoreman::Container.new
    container.get(CONTAINER_NAME)
    case protocol
    when "http"
      container.rport(9200)
    when "transport", "node"
      container.rport(9300)
    end
  end

  def get_client
    Elasticsearch::Client.new(:host => "#{get_host}:#{get_port('http')}")
  end
end

RSpec.configure do |config|
  config.include ESHelper

  # this :all hook gets run before every describe block that is tagged with :integration => true.
  config.before(:all, :integration => true) do
    # check if container exists already before creating new one.
    begin
      ls = Longshoreman::new
      ls.container.get(CONTAINER_NAME)
    rescue Docker::Error::NotFoundError
      Longshoreman.new("#{CONTAINER_IMAGE}:#{CONTAINER_TAG}", CONTAINER_NAME)
      # TODO(talevy): verify ES is running instead of static timeout
      sleep 10
    end
  end

  # we want to do a final cleanup after all :integration runs,
  # but we don't want to clean up before the last block.
  # This is a final blind check to see if the ES docker container is running and
  # needs to be cleaned up. If no container can be found and/or docker is not
  # running on the system, we do nothing.
  config.after(:suite) do
    # only cleanup docker container if system has docker and the container is running
    begin
      ls = Longshoreman::new
      ls.container.get(CONTAINER_NAME)
      ls.cleanup
    rescue Docker::Error::NotFoundError, Excon::Errors::SocketError
      # do nothing
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
logstash-output-elasticsearch-leprechaun-fork-1.0.8 spec/es_spec_helper.rb
logstash-output-elasticsearch-1.1.0-java spec/es_spec_helper.rb
logstash-output-elasticsearch-1.0.7-java spec/es_spec_helper.rb
logstash-output-elasticsearch-1.0.6-java spec/es_spec_helper.rb
logstash-output-elasticsearch-1.0.5-java spec/es_spec_helper.rb
logstash-output-elasticsearch-1.0.4-java spec/es_spec_helper.rb
logstash-output-elasticsearch-1.0.3-java spec/es_spec_helper.rb
logstash-output-elasticsearch-1.0.2-java spec/es_spec_helper.rb
logstash-output-elasticsearch-1.0.1-java spec/es_spec_helper.rb
logstash-output-elasticsearch-1.0.0-java spec/es_spec_helper.rb
logstash-output-elasticsearch-0.2.9-java spec/es_spec_helper.rb