mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
initial spec test for output/file
This commit is contained in:
parent
7a1d2ecd17
commit
dc4aff493d
1 changed files with 72 additions and 0 deletions
72
spec/outputs/file.rb
Normal file
72
spec/outputs/file.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
require "test_utils"
|
||||
require "logstash/outputs/file"
|
||||
require "tempfile"
|
||||
|
||||
describe LogStash::Outputs::File do
|
||||
extend LogStash::RSpec
|
||||
|
||||
describe "ship lots of events to a file" do
|
||||
event_count = 10000 + rand(500)
|
||||
tmp_file = Tempfile.new('logstash-spec-output-file')
|
||||
|
||||
config <<-CONFIG
|
||||
input {
|
||||
generator {
|
||||
message => "hello world"
|
||||
count => #{event_count}
|
||||
type => "generator"
|
||||
}
|
||||
}
|
||||
output {
|
||||
file {
|
||||
path => "#{tmp_file.path}"
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
agent do
|
||||
line_num = 0
|
||||
# Now check all events for order and correctness.
|
||||
File.foreach(tmp_file) do |line|
|
||||
event = LogStash::Event.from_json(line)
|
||||
insist {event.message} == "hello world"
|
||||
insist {event["sequence"]} == line_num
|
||||
line_num += 1
|
||||
end
|
||||
insist {line_num} == event_count
|
||||
end # agent
|
||||
end
|
||||
|
||||
describe "ship lots of events to a file gzipped" do
|
||||
event_count = 10000 + rand(500)
|
||||
tmp_file = Tempfile.new('logstash-spec-output-file')
|
||||
|
||||
config <<-CONFIG
|
||||
input {
|
||||
generator {
|
||||
message => "hello world"
|
||||
count => #{event_count}
|
||||
type => "generator"
|
||||
}
|
||||
}
|
||||
output {
|
||||
file {
|
||||
path => "#{tmp_file.path}"
|
||||
gzip => true
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
agent do
|
||||
line_num = 0
|
||||
# Now check all events for order and correctness.
|
||||
Zlib::GzipReader.new(File.open(tmp_file)).each_line do |line|
|
||||
event = LogStash::Event.from_json(line)
|
||||
insist {event.message} == "hello world"
|
||||
insist {event["sequence"]} == line_num
|
||||
line_num += 1
|
||||
end
|
||||
insist {line_num} == event_count
|
||||
end # agent
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue