Sha256: 98f0a780f66d02e9332ad1b14ee6a56a6c875fa26348bf658cf72a849aa4c0d3

Contents?: true

Size: 1.94 KB

Versions: 25

Compression:

Stored size: 1.94 KB

Contents

require 'test_helper'
require 'logger'

module Elasticsearch
  module Test
    class ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
      startup do
        Elasticsearch::Extensions::Test::Cluster.start(nodes: 2) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?
      end

      shutdown do
        Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] and Elasticsearch::Extensions::Test::Cluster.running?
      end

      context "Elasticsearch client" do
        setup do
          @port  = (ENV['TEST_CLUSTER_PORT'] || 9250).to_i
          system "curl -X DELETE http://localhost:#{@port}/_all > /dev/null 2>&1"

          @logger =  Logger.new(STDERR)
          @logger.formatter = proc do |severity, datetime, progname, msg|
            color = case severity
              when /INFO/ then :green
              when /ERROR|WARN|FATAL/ then :red
              when /DEBUG/ then :cyan
              else :white
            end
            ANSI.ansi(severity[0] + ' ', color, :faint) + ANSI.ansi(msg, :white, :faint) + "\n"
          end

          @client = Elasticsearch::Client.new host: "localhost:#{@port}", logger: (ENV['QUIET'] ? nil : @logger)
        end

        should "perform the API methods" do
          assert_nothing_raised do
            # Index a document
            #
            @client.index index: 'test-index', type: 'test-type', id: '1', body: { title: 'Test' }

            # Refresh the index
            #
            @client.indices.refresh index: 'test-index'

            # Search
            #
            response = @client.search index: 'test-index', body: { query: { match: { title: 'test' } } }

            assert_equal 1,      response['hits']['total']
            assert_equal 'Test', response['hits']['hits'][0]['_source']['title']

            # Delete the index
            #
            @client.indices.delete index: 'test-index'
          end
        end

      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
elasticsearch-1.1.3 test/integration/client_integration_test.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/elasticsearch-5.0.4/test/integration/client_integration_test.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/elasticsearch-5.0.4/test/integration/client_integration_test.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/elasticsearch-5.0.4/test/integration/client_integration_test.rb
elasticsearch-5.0.4 test/integration/client_integration_test.rb
elasticsearch-2.0.2 test/integration/client_integration_test.rb
elasticsearch-5.0.3 test/integration/client_integration_test.rb
elasticsearch-5.0.2 test/integration/client_integration_test.rb
elasticsearch-5.0.1 test/integration/client_integration_test.rb
elasticsearch-2.0.1 test/integration/client_integration_test.rb
elasticsearch-1.1.2 test/integration/client_integration_test.rb
elasticsearch-5.0.0 test/integration/client_integration_test.rb
elasticsearch-5.0.0.pre test/integration/client_integration_test.rb
elasticsearch-2.0.0 test/integration/client_integration_test.rb
elasticsearch-1.1.0 test/integration/client_integration_test.rb
elasticsearch-2.0.0.pre test/integration/client_integration_test.rb
elasticsearch-1.1.pre test/integration/client_integration_test.rb
elasticsearch-1.0.18 test/integration/client_integration_test.rb
elasticsearch-1.0.17 test/integration/client_integration_test.rb
elasticsearch-1.0.16 test/integration/client_integration_test.rb