Skip to content

Commit 3acd4eb

Browse files
authored
test: add in_http multipart test case (fluent#4901)
**Which issue(s) this PR fixes**: None. **What this PR does / why we need it**: Add a test for `in_http` multipart content-type. There is no test case for this. We need it. **Docs Changes**: Not needed. **Release Note**: Not needed. Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
1 parent 2f8cce7 commit 3acd4eb

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/fluent/test/helpers.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def event_time(str=nil, format: nil)
5050
end
5151
end
5252

53+
def event_time_without_nsec(str=nil, format: nil)
54+
Fluent::EventTime.new(event_time(str, format: format))
55+
end
56+
5357
def with_timezone(tz)
5458
oldtz, ENV['TZ'] = ENV['TZ'], tz
5559
yield

test/plugin/test_in_http.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,28 @@ def test_application_ndjson
584584
assert_equal(expected, d.events)
585585
end
586586

587+
def test_multipart_formdata
588+
tag = "tag"
589+
time = event_time_without_nsec
590+
event = [tag, time, {"key" => 0}]
591+
body = "--TESTBOUNDARY\r\n" +
592+
"Content-Disposition: form-data; name=\"json\"\r\n" +
593+
"\r\n" +
594+
%[{"key":0}\r\n] +
595+
"--TESTBOUNDARY\r\n"
596+
597+
d = create_driver
598+
res = nil
599+
d.run(expect_records: 1) do
600+
res = post("/#{tag}?time=#{time.to_s}", body, {"Content-Type"=>"multipart/form-data; boundary=TESTBOUNDARY"})
601+
end
602+
603+
assert_equal(
604+
["200", [event]],
605+
[res.code, d.events],
606+
)
607+
end
608+
587609
def test_msgpack
588610
d = create_driver
589611
time = event_time("2011-01-02 13:14:15 UTC")
@@ -1136,10 +1158,10 @@ def options(path, params, header = {})
11361158
http.request(req)
11371159
end
11381160

1139-
def post(path, params, header = {}, &block)
1161+
def post(path, params, header = {})
11401162
http = Net::HTTP.new("127.0.0.1", @port)
11411163
req = Net::HTTP::Post.new(path, header)
1142-
block.call(http, req) if block
1164+
yield http, req if block_given?
11431165
if params.is_a?(String)
11441166
unless header.has_key?('Content-Type')
11451167
header['Content-Type'] = 'application/octet-stream'

0 commit comments

Comments
 (0)