From 95cf25eb33efb096b291a9eac8e56f2f2c3d1d75 Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Thu, 10 Apr 2025 16:43:29 +0900 Subject: [PATCH] test: add in_http multipart test case Signed-off-by: Daijiro Fukuda --- lib/fluent/test/helpers.rb | 4 ++++ test/plugin/test_in_http.rb | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/fluent/test/helpers.rb b/lib/fluent/test/helpers.rb index 26b224a989..6fdfbf29ff 100644 --- a/lib/fluent/test/helpers.rb +++ b/lib/fluent/test/helpers.rb @@ -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 diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb index 68af20232d..413ff904f7 100644 --- a/test/plugin/test_in_http.rb +++ b/test/plugin/test_in_http.rb @@ -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") @@ -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'