Module: LogStashHelper

Defined in:
lib/logstash/devutils/rspec/logstash_helpers.rb

Instance Method Summary collapse

Instance Method Details

#agent(&block) ⇒ Object

def input



67
68
69
70
71
72
73
74
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 67

def agent(&block)

  it("agent(#{caller[0].gsub(/ .*/, "")}) runs") do
    pipeline = LogStash::Pipeline.new(config)
    pipeline.run
    block.call
  end
end

#config(configstr) ⇒ Object



7
8
9
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 7

def config(configstr)
  let(:config) { configstr }
end

#input(&block) ⇒ Object

def sample



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 55

def input(&block)
  it "inputs" do
    pipeline = LogStash::Pipeline.new(config)
    queue = Queue.new
    pipeline.instance_eval do
      @output_func = lambda { |event| queue << event }
    end
    block.call(pipeline, queue)
    pipeline.shutdown
  end
end

#sample(sample_event, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 20

def sample(sample_event, &block)
  name = sample_event.is_a?(String) ? sample_event : LogStash::Json.dump(sample_event)
  name = name[0..50] + "..." if name.length > 50

  describe "\"#{name}\"" do
    let(:pipeline) { LogStash::Pipeline.new(config) }
    let(:event) do
      sample_event = [sample_event] unless sample_event.is_a?(Array)
      next sample_event.collect do |e|
        e = { "message" => e } if e.is_a?(String)
        next LogStash::Event.new(e)
      end
    end

    let(:results) do
      results = []
      pipeline.instance_eval { @filters.each(&:register) }

      event.each do |e|
        pipeline.filter(e) {|new_event| results << new_event }
      end

      pipeline.flush_filters(:final => true) do |e|
        results << e unless e.cancelled?
      end

      results
    end

    subject { results.length > 1 ? results: results.first }

    it("when processed", &block)
  end
end

#tags(*tags) ⇒ Object



15
16
17
18
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 15

def tags(*tags)
  let(:default_tags) { tags }
  puts "Setting default tags: #{tags}"
end

#type(default_type) ⇒ Object

def config



11
12
13
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 11

def type(default_type)
  let(:default_type) { default_type }
end