Skip to content

test: add in_http multipart test case #4901

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/fluent/test/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def event_time(str=nil, format: nil)
end
end

def event_time_without_nsec(str=nil, format: nil)
Fluent::EventTime.new(event_time(str, format: format))
end

def with_timezone(tz)
oldtz, ENV['TZ'] = ENV['TZ'], tz
yield
Expand Down
26 changes: 24 additions & 2 deletions test/plugin/test_in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,28 @@ def test_application_ndjson
assert_equal(expected, d.events)
end

def test_multipart_formdata
tag = "tag"
time = event_time_without_nsec
event = [tag, time, {"key" => 0}]
body = "--TESTBOUNDARY\r\n" +
"Content-Disposition: form-data; name=\"json\"\r\n" +
"\r\n" +
%[{"key":0}\r\n] +
"--TESTBOUNDARY\r\n"

d = create_driver
res = nil
d.run(expect_records: 1) do
res = post("/#{tag}?time=#{time.to_s}", body, {"Content-Type"=>"multipart/form-data; boundary=TESTBOUNDARY"})
end

assert_equal(
["200", [event]],
[res.code, d.events],
)
end

def test_msgpack
d = create_driver
time = event_time("2011-01-02 13:14:15 UTC")
Expand Down Expand Up @@ -1136,10 +1158,10 @@ def options(path, params, header = {})
http.request(req)
end

def post(path, params, header = {}, &block)
def post(path, params, header = {})
http = Net::HTTP.new("127.0.0.1", @port)
req = Net::HTTP::Post.new(path, header)
block.call(http, req) if block
yield http, req if block_given?
if params.is_a?(String)
unless header.has_key?('Content-Type')
header['Content-Type'] = 'application/octet-stream'
Expand Down