Repository navigation
Raise an error when the host is empty after placeholder expansion #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -445,4 +445,67 @@ def test_severity_mapper(data) | |||||||
| out = Fluent::Plugin::RemoteSyslogOutput::SeverityMapper.map(data[:in]) | ||||||||
| assert_equal(data[:out], out) | ||||||||
| end | ||||||||
|
|
||||||||
| data("host udp", {target: %[host "${dest}"\nport 5568], protocol: "udp"}) | ||||||||
| data("host tcp", {target: %[host "${dest}"\nport 5568], protocol: "tcp"}) | ||||||||
| data("host_with_port udp", {target: %[host_with_port "${dest}:5568"], protocol: "udp"}) | ||||||||
| data("host_with_port tcp", {target: %[host_with_port "${dest}:5568"], protocol: "tcp"}) | ||||||||
| data("host_with_port without port", {target: %[host_with_port "${dest}"], protocol: "udp"}) | ||||||||
| def test_write_raises_on_empty_host(data) | ||||||||
| d = create_driver_out_syslog %[ | ||||||||
| @type remote_syslog | ||||||||
| #{data[:target]} | ||||||||
| protocol #{data[:protocol]} | ||||||||
|
|
||||||||
| <buffer dest> | ||||||||
| </buffer> | ||||||||
|
|
||||||||
| <format> | ||||||||
| @type single_value | ||||||||
| message_key message | ||||||||
| </format> | ||||||||
| ] | ||||||||
|
|
||||||||
| time = Fluent::EventTime.now | ||||||||
| record = {"message" => "hello"} | ||||||||
| chunk = Fluent::Plugin::Buffer::MemoryChunk.new(d.instance.metadata("tag", time, record)) | ||||||||
| chunk.append([d.instance.format("tag", time, record)]) | ||||||||
|
|
||||||||
| error = assert_raise(Fluent::UnrecoverableError) { d.instance.write(chunk) } | ||||||||
| assert_match(/host is empty/, error.message) | ||||||||
| end | ||||||||
|
|
||||||||
| data("host with a port", {target: %[host ""\nport 5571], port: 5571}) | ||||||||
| data("host_with_port", {target: %[host_with_port ":5572"], port: 5572}) | ||||||||
| def test_write_with_empty_configured_host_sends_to_local_host(data) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MUST: This test fails on the
Suggested change
|
||||||||
| d = create_driver_out_syslog %[ | ||||||||
| @type remote_syslog | ||||||||
| #{data[:target]} | ||||||||
| program minitest | ||||||||
| protocol tcp | ||||||||
|
|
||||||||
| <format> | ||||||||
| @type single_value | ||||||||
| message_key message | ||||||||
| </format> | ||||||||
| ] | ||||||||
|
|
||||||||
| server = TCPServer.new("127.0.0.1", data[:port]) | ||||||||
| received = Thread.new do | ||||||||
| client = server.accept | ||||||||
| line = client.gets | ||||||||
| client.close | ||||||||
| line | ||||||||
| end | ||||||||
| begin | ||||||||
| d.run do | ||||||||
| d.feed("tag", Fluent::EventTime.now, {"message" => "hello"}) | ||||||||
| end | ||||||||
| assert_not_nil(received.join(5), "no message received") | ||||||||
| assert_match(/minitest: hello/, received.value) | ||||||||
| ensure | ||||||||
| received.kill | ||||||||
| server.close | ||||||||
| end | ||||||||
| end | ||||||||
| end | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT:
host_with_port "${dest}"(without a port) reaches thehost.nil?side of the check, because"".split(":")returns[]. None of the four cases covers it. Could you add it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the
host_with_port without portcase in 0362839.bundle exec rake test: 47 tests, 0 failures.