mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
- use more let() statements instead of local scoping things
This is an attempt to fix two specs that clobber eachother, but it did not fix anything. Still, this is easier to read now.
This commit is contained in:
parent
559156ff5a
commit
780cb9bfce
1 changed files with 17 additions and 18 deletions
|
@ -25,33 +25,33 @@ end
|
|||
module LogStash
|
||||
module RSpec
|
||||
def config(configstr)
|
||||
@config_str = configstr
|
||||
let(:config) { configstr }
|
||||
end # def config
|
||||
|
||||
def type(default_type)
|
||||
@default_type = default_type
|
||||
let(:default_type) { default_type }
|
||||
end
|
||||
|
||||
def tags(*tags)
|
||||
@default_tags = tags
|
||||
let(: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
|
||||
def sample(sample_event, &block)
|
||||
name = sample_event.is_a?(String) ? sample_event : sample_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|
|
||||
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 = []
|
||||
count = 0
|
||||
pipeline.instance_eval { @filters.each(&:register) }
|
||||
|
@ -66,19 +66,19 @@ module LogStash
|
|||
|
||||
# TODO(sissel): pipeline flush needs to be implemented.
|
||||
#results += pipeline.flush
|
||||
@results = results
|
||||
end # before :all
|
||||
next results
|
||||
end
|
||||
|
||||
subject { results.length > 1 ? results: results.first }
|
||||
|
||||
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)
|
||||
pipeline = LogStash::Pipeline.new(config)
|
||||
#(class << pipeline; self; end).send(:define_method, :output) do |event|
|
||||
#p :event => event
|
||||
#queue << event
|
||||
|
@ -94,11 +94,10 @@ module LogStash
|
|||
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 = LogStash::Pipeline.new(config)
|
||||
pipeline.run
|
||||
@duration = ::Time.now - start
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue