mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Merge pull request #633 from wiibaa/spec-output-file
Correct test case spec/output/file.rb
This commit is contained in:
commit
42f11e3bec
2 changed files with 15 additions and 13 deletions
|
@ -57,18 +57,10 @@ class LogStash::Event
|
||||||
data["@version"] = "1" if !@data.include?("@version")
|
data["@version"] = "1" if !@data.include?("@version")
|
||||||
end # def initialize
|
end # def initialize
|
||||||
|
|
||||||
# Add class methods on inclusion.
|
|
||||||
public
|
public
|
||||||
def self.included(klass)
|
def self.from_json(json)
|
||||||
klass.extend(ClassMethods)
|
return self.new(JSON.parse(json))
|
||||||
end # def included
|
end # def from_json
|
||||||
|
|
||||||
module ClassMethods
|
|
||||||
public
|
|
||||||
def from_json(json)
|
|
||||||
return self.new(JSON.parse(json))
|
|
||||||
end # def from_json
|
|
||||||
end
|
|
||||||
|
|
||||||
public
|
public
|
||||||
def cancel
|
def cancel
|
||||||
|
|
|
@ -29,7 +29,7 @@ describe LogStash::Outputs::File do
|
||||||
# Now check all events for order and correctness.
|
# Now check all events for order and correctness.
|
||||||
File.foreach(tmp_file) do |line|
|
File.foreach(tmp_file) do |line|
|
||||||
event = LogStash::Event.from_json(line)
|
event = LogStash::Event.from_json(line)
|
||||||
insist {event.message} == "hello world"
|
insist {event["message"]} == "hello world"
|
||||||
insist {event["sequence"]} == line_num
|
insist {event["sequence"]} == line_num
|
||||||
line_num += 1
|
line_num += 1
|
||||||
end
|
end
|
||||||
|
@ -62,7 +62,17 @@ describe LogStash::Outputs::File do
|
||||||
# Now check all events for order and correctness.
|
# Now check all events for order and correctness.
|
||||||
Zlib::GzipReader.new(File.open(tmp_file)).each_line do |line|
|
Zlib::GzipReader.new(File.open(tmp_file)).each_line do |line|
|
||||||
event = LogStash::Event.from_json(line)
|
event = LogStash::Event.from_json(line)
|
||||||
insist {event.message} == "hello world"
|
insist {event["message"]} == "hello world"
|
||||||
|
insist {event["sequence"]} == line_num
|
||||||
|
line_num += 1
|
||||||
|
end
|
||||||
|
insist {line_num} == event_count
|
||||||
|
|
||||||
|
#LOGSTASH-997 confirm usage of zcat command on file
|
||||||
|
line_num = 0
|
||||||
|
`zcat #{tmp_file.path()}`.split("\n").each do |line|
|
||||||
|
event = LogStash::Event.from_json(line)
|
||||||
|
insist {event["message"]} == "hello world"
|
||||||
insist {event["sequence"]} == line_num
|
insist {event["sequence"]} == line_num
|
||||||
line_num += 1
|
line_num += 1
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue