Sha256: e36798c52ca8869f05ea48e74c97fcb983652f1fb225da288a7999c3fb609097

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

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

describe "inputs/generator" do

  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]["sequence"] } == 0
    insist { events[0]["message"] } == "foo"

    insist { events[1]["sequence"] } == 1
    insist { events[1]["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
    stdin_mock.should_receive(:readline).once.and_return("bar")

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

    insist { events[0]["sequence"] } == 0
    insist { events[0]["message"] } == "bar"

    insist { events[1]["sequence"] } == 1
    insist { events[1]["message"] } == "bar"

    $stdin = saved_stdin
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
logstash-input-generator-1.0.0 spec/inputs/generator_spec.rb
logstash-input-generator-0.1.5 spec/inputs/generator_spec.rb
logstash-input-generator-0.1.4 spec/inputs/generator_spec.rb