mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Revert "Revert "- use more let() statements instead of local scoping things""
This reverts commit 87c46c3345
.
This commit is contained in:
parent
1087b92b9c
commit
40217a8e7f
1 changed files with 17 additions and 18 deletions
|
@ -25,33 +25,33 @@ end
|
||||||
module LogStash
|
module LogStash
|
||||||
module RSpec
|
module RSpec
|
||||||
def config(configstr)
|
def config(configstr)
|
||||||
@config_str = configstr
|
let(:config) { configstr }
|
||||||
end # def config
|
end # def config
|
||||||
|
|
||||||
def type(default_type)
|
def type(default_type)
|
||||||
@default_type = default_type
|
let(:default_type) { default_type }
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags(*tags)
|
def tags(*tags)
|
||||||
@default_tags = tags
|
let(:default_tags) { tags }
|
||||||
puts "Setting default tags: #{@default_tags}"
|
puts "Setting default tags: #{@default_tags}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def sample(event, &block)
|
def sample(sample_event, &block)
|
||||||
pipeline = LogStash::Pipeline.new(@config_str)
|
name = sample_event.is_a?(String) ? sample_event : sample_event.to_json
|
||||||
|
|
||||||
name = event.is_a?(String) ? event : event.to_json
|
|
||||||
name = name[0..50] + "..." if name.length > 50
|
name = name[0..50] + "..." if name.length > 50
|
||||||
|
|
||||||
describe "\"#{name}\"" do
|
describe "\"#{name}\"" do
|
||||||
before :each do
|
let(:pipeline) { LogStash::Pipeline.new(config) }
|
||||||
# Coerce to an array of LogStash::Event
|
let(:event) do
|
||||||
event = [event] unless event.is_a?(Array)
|
sample_event = [sample_event] unless sample_event.is_a?(Array)
|
||||||
event = event.collect do |e|
|
next sample_event.collect do |e|
|
||||||
e = { "message" => e } if e.is_a?(String)
|
e = { "message" => e } if e.is_a?(String)
|
||||||
next LogStash::Event.new(e)
|
next LogStash::Event.new(e)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:results) do
|
||||||
results = []
|
results = []
|
||||||
count = 0
|
count = 0
|
||||||
pipeline.instance_eval { @filters.each(&:register) }
|
pipeline.instance_eval { @filters.each(&:register) }
|
||||||
|
@ -66,19 +66,19 @@ module LogStash
|
||||||
|
|
||||||
# TODO(sissel): pipeline flush needs to be implemented.
|
# TODO(sissel): pipeline flush needs to be implemented.
|
||||||
#results += pipeline.flush
|
#results += pipeline.flush
|
||||||
@results = results
|
next results
|
||||||
end # before :all
|
end
|
||||||
|
|
||||||
|
subject { results.length > 1 ? results: results.first }
|
||||||
|
|
||||||
subject { @results.length > 1 ? @results: @results.first }
|
|
||||||
it("when processed", &block)
|
it("when processed", &block)
|
||||||
end
|
end
|
||||||
end # def sample
|
end # def sample
|
||||||
|
|
||||||
def input(&block)
|
def input(&block)
|
||||||
config_str = @config_str
|
|
||||||
it "inputs" do
|
it "inputs" do
|
||||||
queue = Queue.new
|
queue = Queue.new
|
||||||
pipeline = LogStash::Pipeline.new(config_str)
|
pipeline = LogStash::Pipeline.new(config)
|
||||||
#(class << pipeline; self; end).send(:define_method, :output) do |event|
|
#(class << pipeline; self; end).send(:define_method, :output) do |event|
|
||||||
#p :event => event
|
#p :event => event
|
||||||
#queue << event
|
#queue << event
|
||||||
|
@ -94,11 +94,10 @@ module LogStash
|
||||||
require "logstash/pipeline"
|
require "logstash/pipeline"
|
||||||
|
|
||||||
# scoping is hard, let's go shopping!
|
# scoping is hard, let's go shopping!
|
||||||
config_str = @config_str
|
|
||||||
describe "agent(#{@agent_count}) #{caller[1]}" do
|
describe "agent(#{@agent_count}) #{caller[1]}" do
|
||||||
before :each do
|
before :each do
|
||||||
start = ::Time.now
|
start = ::Time.now
|
||||||
pipeline = LogStash::Pipeline.new(config_str)
|
pipeline = LogStash::Pipeline.new(config)
|
||||||
pipeline.run
|
pipeline.run
|
||||||
@duration = ::Time.now - start
|
@duration = ::Time.now - start
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue