spec/inputs/file_spec.rb in logstash-input-file-2.2.5 vs spec/inputs/file_spec.rb in logstash-input-file-3.0.0
- old
+ new
@@ -43,12 +43,12 @@
events = input(conf) do |pipeline, queue|
2.times.collect { queue.pop }
end
- insist { events[0]["message"] } == "hello"
- insist { events[1]["message"] } == "world"
+ insist { events[0].get("message") } == "hello"
+ insist { events[1].get("message") } == "world"
end
it "should restarts at the sincedb value" do
tmpfile_path = Stud::Temporary.pathname
sincedb_path = Stud::Temporary.pathname
@@ -72,12 +72,12 @@
events = input(conf) do |pipeline, queue|
2.times.collect { queue.pop }
end
- insist { events[0]["message"] } == "hello3"
- insist { events[1]["message"] } == "world3"
+ insist { events[0].get("message") } == "hello3"
+ insist { events[1].get("message") } == "world3"
File.open(tmpfile_path, "a") do |fd|
fd.puts("foo")
fd.puts("bar")
fd.puts("baz")
@@ -86,13 +86,13 @@
events = input(conf) do |pipeline, queue|
3.times.collect { queue.pop }
end
- insist { events[0]["message"] } == "foo"
- insist { events[1]["message"] } == "bar"
- insist { events[2]["message"] } == "baz"
+ insist { events[0].get("message") } == "foo"
+ insist { events[1].get("message") } == "bar"
+ insist { events[2].get("message") } == "baz"
end
it "should not overwrite existing path and host fields" do
tmpfile_path = Stud::Temporary.pathname
sincedb_path = Stud::Temporary.pathname
@@ -118,15 +118,15 @@
events = input(conf) do |pipeline, queue|
2.times.collect { queue.pop }
end
- insist { events[0]["path"] } == "my_path"
- insist { events[0]["host"] } == "my_host"
+ insist { events[0].get("path") } == "my_path"
+ insist { events[0].get("host") } == "my_host"
- insist { events[1]["path"] } == "#{tmpfile_path}"
- insist { events[1]["host"] } == "#{Socket.gethostname.force_encoding(Encoding::UTF_8)}"
+ insist { events[1].get("path") } == "#{tmpfile_path}"
+ insist { events[1].get("host") } == "#{Socket.gethostname.force_encoding(Encoding::UTF_8)}"
end
context "when sincedb_path is an existing directory" do
let(:tmpfile_path) { Stud::Temporary.pathname }
let(:sincedb_path) { Stud::Temporary.directory }
@@ -187,19 +187,19 @@
subject.run(events)
event1 = events[0]
expect(event1).not_to be_nil
- expect(event1["path"]).to eq tmpfile_path
- expect(event1["@metadata"]["path"]).to eq tmpfile_path
- expect(event1["message"]).to eq "hello"
+ expect(event1.get("path")).to eq tmpfile_path
+ expect(event1.get("[@metadata][path]")).to eq tmpfile_path
+ expect(event1.get("message")).to eq "hello"
event2 = events[1]
expect(event2).not_to be_nil
- expect(event2["path"]).to eq tmpfile_path
- expect(event2["@metadata"]["path"]).to eq tmpfile_path
- expect(event2["message"]).to eq "world"
+ expect(event2.get("path")).to eq tmpfile_path
+ expect(event2.get("[@metadata][path]")).to eq tmpfile_path
+ expect(event2.get("message")).to eq "world"
end
end
context "when close_older config is specified" do
let(:line) { "line1.1-of-a" }
@@ -310,22 +310,22 @@
subject.stop
end
.then_after(0.2 , "stop flushes both events") do
expect(events.size).to eq(2)
e1, e2 = events
- e1_message = e1["message"]
- e2_message = e2["message"]
+ e1_message = e1.get("message")
+ e2_message = e2.get("message")
# can't assume File A will be read first
if e1_message.start_with?('line1.1-of-z')
- expect(e1["path"]).to match(/z.log/)
- expect(e2["path"]).to match(/A.log/)
+ expect(e1.get("path")).to match(/z.log/)
+ expect(e2.get("path")).to match(/A.log/)
expect(e1_message).to eq("line1.1-of-z#{FILE_DELIMITER} line1.2-of-z#{FILE_DELIMITER} line1.3-of-z")
expect(e2_message).to eq("line1.1-of-a#{FILE_DELIMITER} line1.2-of-a#{FILE_DELIMITER} line1.3-of-a")
else
- expect(e1["path"]).to match(/A.log/)
- expect(e2["path"]).to match(/z.log/)
+ expect(e1.get("path")).to match(/A.log/)
+ expect(e2.get("path")).to match(/z.log/)
expect(e1_message).to eq("line1.1-of-a#{FILE_DELIMITER} line1.2-of-a#{FILE_DELIMITER} line1.3-of-a")
expect(e2_message).to eq("line1.1-of-z#{FILE_DELIMITER} line1.2-of-z#{FILE_DELIMITER} line1.3-of-z")
end
end
subject.run(events)
@@ -345,11 +345,11 @@
fd.puts(" line1.3-of-a")
end
end
.then_after(0.75, "wait for auto_flush") do
e1 = events.first
- e1_message = e1["message"]
+ e1_message = e1.get("message")
expect(e1["path"]).to match(/a.log/)
expect(e1_message).to eq("line1.1-of-a#{FILE_DELIMITER} line1.2-of-a#{FILE_DELIMITER} line1.3-of-a")
end
.then("stop") do
subject.stop
@@ -441,15 +441,15 @@
.then_after(0.1, "stop flushes last event") do
expect(events.size).to eq(2)
e1, e2 = events
if Dir.glob("#{tmpdir_path}/*.log").first =~ %r{a\.log}
#linux and OSX have different retrieval order
- expect(e1["message"]).to eq("line1-of-a")
- expect(e2["message"]).to eq("line2-of-a")
+ expect(e1.get("message")).to eq("line1-of-a")
+ expect(e2.get("message")).to eq("line2-of-a")
else
- expect(e1["message"]).to eq("line1-of-z")
- expect(e2["message"]).to eq("line2-of-z")
+ expect(e1.get("message")).to eq("line1-of-z")
+ expect(e2.get("message")).to eq("line2-of-z")
end
end
subject.run(events)
# wait for actions future value
actions.value
@@ -482,22 +482,21 @@
#linux and OSX have different retrieval order
e1, e2, e3, e4 = events
else
e3, e4, e1, e2 = events
end
- expect(e1["message"]).to eq("line1-of-a")
- expect(e2["message"]).to eq("line2-of-a")
- expect(e3["message"]).to eq("line1-of-z")
- expect(e4["message"]).to eq("line2-of-z")
+ expect(e1.get("message")).to eq("line1-of-a")
+ expect(e2.get("message")).to eq("line2-of-a")
+ expect(e3.get("message")).to eq("line1-of-z")
+ expect(e4.get("message")).to eq("line2-of-z")
end
.then_after(0.1, "stop") do
subject.stop
end
subject.run(events)
# wait for actions future value
actions.value
end
end
-
end
end
end