Sha256: c882672c9429148db306446421ea3f385be851d6579be61be1d3ec2161572086

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

require "logstash/devutils/rspec/spec_helper"
require "logstash/inputs/generator"

describe LogStash::Inputs::Generator do

  it_behaves_like "an interruptible input plugin" do
    let(:config) { { } }
  end

  it "should generate configured message" do
    conf = <<-CONFIG
      input {
        generator {
          count => 2
          message => "foo"
        }
      }
    CONFIG

    events = input(conf) do |pipeline, queue|
      2.times.map{queue.pop}
    end

    insist { events[0].get("sequence") } == 0
    insist { events[0].get("message") } == "foo"

    insist { events[1].get("sequence") } == 1
    insist { events[1].get("message") } == "foo"
  end

  it "should generate message from stdin" do
    conf = <<-CONFIG
      input {
        generator {
          count => 2
          message => "stdin"
        }
      }
    CONFIG

    saved_stdin = $stdin
    stdin_mock = StringIO.new
    $stdin = stdin_mock
    expect(stdin_mock).to receive(:readline).once.and_return("bar")

    events = input(conf) do |pipeline, queue|
      2.times.map{queue.pop}
    end

    insist { events[0].get("sequence") } == 0
    insist { events[0].get("message") } == "bar"

    insist { events[1].get("sequence") } == 1
    insist { events[1].get("message") } == "bar"

    $stdin = saved_stdin
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
logstash-input-generator-3.0.6 spec/inputs/generator_spec.rb
logstash-input-generator-3.0.5 spec/inputs/generator_spec.rb
logstash-input-generator-3.0.4 spec/inputs/generator_spec.rb
logstash-input-generator-3.0.3 spec/inputs/generator_spec.rb
logstash-input-generator-3.0.2 spec/inputs/generator_spec.rb
logstash-input-generator-3.0.1 spec/inputs/generator_spec.rb
logstash-input-generator-3.0.0 spec/inputs/generator_spec.rb