logstash/spec/test_utils.rb
Jordan Sissel af538da782 - log the compiled code more readably
- clarify rbx issues indicating that I haven't really done any debugging
to figure out where the problem is.
- update changelog with todos
- remove unused require
- try to fix up require() debugger
2013-07-22 13:48:15 -07:00

121 lines
3.1 KiB
Ruby

require "insist"
require "logstash/agent"
require "logstash/pipeline"
require "logstash/event"
require "logstash/logging"
require "insist"
require "stud/try"
$TESTING = true
if RUBY_VERSION < "1.9.2"
$stderr.puts "Ruby 1.9.2 or later is required. (You are running: " + RUBY_VERSION + ")"
$stderr.puts "Options for fixing this: "
$stderr.puts " * If doing 'ruby bin/logstash ...' add --1.9 flag to 'ruby'"
$stderr.puts " * If doing 'java -jar ... ' add -Djruby.compat.version=RUBY1_9 to java flags"
raise LoadError
end
$logger = LogStash::Logger.new(STDOUT)
if ENV["TEST_DEBUG"]
$logger.level = :debug
else
$logger.level = :error
end
module LogStash
module RSpec
def config(configstr)
@config_str = configstr
end # def config
def type(default_type)
@default_type = default_type
end
def tags(*tags)
@default_tags = tags
puts "Setting default tags: #{@default_tags}"
end
def sample(event, &block)
pipeline = LogStash::Pipeline.new(@config_str)
name = event.is_a?(String) ? event : event.to_json
name = name[0..50] + "..." if name.length > 50
describe "\"#{name}\"" do
before :each do
# Coerce to an array of LogStash::Event
event = [event] unless event.is_a?(Array)
event = event.collect do |e|
e = { "message" => e } if e.is_a?(String)
next LogStash::Event.new(e)
end
results = []
count = 0
pipeline.instance_eval { @filters.each(&:register) }
event.each do |e|
extra = []
pipeline.filter(e) do |new_event|
extra << new_event
end
results << e if !e.cancelled?
results += extra.reject(&:cancelled?)
end
# TODO(sissel): pipeline flush needs to be implemented.
#results += pipeline.flush
@results = results
end # before :all
subject { @results.length > 1 ? @results: @results.first }
it("when processed", &block)
end
end # def sample
def input(&block)
config_str = @config_str
it "inputs" do
queue = Queue.new
pipeline = LogStash::Pipeline.new(config_str)
#(class << pipeline; self; end).send(:define_method, :output) do |event|
#p :event => event
#queue << event
#end
#p pipeline.method(:output)
block.call(pipeline, queue)
pipeline.shutdown
end
end # def input
def agent(&block)
@agent_count ||= 0
require "logstash/pipeline"
# scoping is hard, let's go shopping!
config_str = @config_str
describe "agent(#{@agent_count}) #{caller[1]}" do
before :each do
start = ::Time.now
pipeline = LogStash::Pipeline.new(config_str)
pipeline.run
@duration = ::Time.now - start
end
it("looks good", &block)
end
@agent_count += 1
end # def agent
end # module RSpec
end # module LogStash
class Shiftback
def initialize(&block)
@block = block
end
def <<(event)
@block.call(event)
end
end # class Shiftback