Skip to content

Commit

Permalink
add tests: no overwriting of 'path' and 'host' fields
Browse files Browse the repository at this point in the history
  • Loading branch information
talevy committed May 16, 2015
1 parent 7724fb5 commit 7570ac4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions logstash-input-file.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ Gem::Specification.new do |s|

s.add_development_dependency 'stud', ['~> 0.0.19']
s.add_development_dependency 'logstash-devutils'
s.add_development_dependency 'logstash-codec-json'
end

33 changes: 33 additions & 0 deletions spec/inputs/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,37 @@
insist { events[1]["message"] } == "bar"
insist { events[2]["message"] } == "baz"
end

it "should not overwrite existing path and host fields" do
tmpfile_path = Stud::Temporary.pathname
sincedb_path = Stud::Temporary.pathname

conf = <<-CONFIG
input {
file {
type => "blah"
path => "#{tmpfile_path}"
start_position => "beginning"
sincedb_path => "#{sincedb_path}"
delimiter => "#{delimiter}"
codec => "json"
}
}
CONFIG

File.open(tmpfile_path, "w") do |fd|
fd.puts('{"path": "my_path", "host": "my_host"}')
fd.puts('{"my_field": "my_val"}')
end

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[1]["path"] } == "#{tmpfile_path}"
insist { events[1]["host"] } == "#{Socket.gethostname.force_encoding(Encoding::UTF_8)}"
end
end

0 comments on commit 7570ac4

Please sign in to comment.