Sha256: 17d653af7e7965ba057ea24fe5072a6cdb202e3188f145f34ab8a666d15a405e

Contents?: true

Size: 1.62 KB

Versions: 4

Compression:

Stored size: 1.62 KB

Contents

# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require "logstash/plugin"
require "logstash/filters/opensearch"
require_relative "../../../spec/opensearch_helper"

describe LogStash::Filters::OpenSearch, :integration => true do


  let(:config) do
    {
      "index" => 'logs',
      "hosts" => [OpenSearchHelper.get_host_port],
      "query" => "response: 404",
      "sort" => "response",
      "fields" => [ ["response", "code"] ],
    }
  end
  let(:plugin) { described_class.new(config) }
  let(:event)  { LogStash::Event.new({}) }

  before(:each) do
    @opensearch = OpenSearchHelper.get_client
    # Delete all templates first.
    # Clean ES of data before we start.
    @opensearch.indices.delete_template(:name => "*")
    # This can fail if there are no indexes, ignore failure.
    @opensearch.indices.delete(:index => "*") rescue nil
    10.times do
      OpenSearchHelper.index_doc(@opensearch, :index => 'logs', :body => { :response => 404, :this => 'that'})
    end
    @opensearch.indices.refresh

    plugin.register
  end

  it "should enhance the current event with new data" do
    plugin.filter(event)
    expect(event.get('code')).to eq(404)
  end

  context "when retrieving a list of elements" do

    let(:config) do
      {
        "index" => 'logs',
        "hosts" => [OpenSearchHelper.get_host_port],
        "query" => "response: 404",
        "fields" => [ ["response", "code"] ],
        "sort" => "response",
        "result_size" => 10
      }
    end

    it "should enhance the current event with new data" do
      plugin.filter(event)
      expect(event.get("code")).to eq([404]*10)
    end

  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
logstash-filter-opensearch-0.1.1 spec/filters/integration/opensearch_spec.rb
logstash-filter-opensearch-manticore-0.1.1 spec/filters/integration/opensearch_spec.rb
logstash-filter-opensearch-manticore-0.1.0 spec/filters/integration/opensearch_spec.rb
logstash-filter-opensearch-0.1.0 spec/filters/integration/opensearch_spec.rb