Skip to content

Commit 1a3104a

Browse files
author
sskim
committed
add req/res header testcase
1 parent 53a0ce1 commit 1a3104a

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

test/helper/stub_server.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def initialize
1111
@server.mount_proc '/internal_error', &method(:internal_error)
1212
@server.mount_proc '/redirect', &method(:redirect)
1313
@server.mount_proc '/protected', &method(:protected)
14+
@server.mount_proc '/custom_header', &method(:custom_header)
1415
end
1516

1617
def start
@@ -81,4 +82,12 @@ def protected(req, res)
8182
res['Content-Type'] = 'application/json'
8283
res.body = '{ "status": "OK" }'
8384
end
85+
86+
def custom_header(req, res)
87+
res.header["HATSUNE-MIKU"] = req["HATSUNE-MIKU"] if req["HATSUNE-MIKU"]
88+
89+
res.status = 200
90+
res['Content-Type'] = 'application/json'
91+
res.body = '{ "status": "OK" }'
92+
end
8493
end

test/plugin/test_in_http_pull.rb

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,23 @@ class HttpPullInputTest < Test::Unit::TestCase
466466
</response_header>
467467
]
468468

469-
test 'interval 3' do
469+
TEST_INTERVAL_3_RES_MULTI_HEADER_CONFIG = %[
470+
tag test
471+
url http://127.0.0.1:3939
472+
473+
interval 3s
474+
format json
475+
476+
<response_header>
477+
header Content-Type
478+
</response_header>
479+
480+
<response_header>
481+
header Content-Length
482+
</response_header>
483+
]
484+
485+
test 'interval 3 with single header' do
470486
d = create_driver TEST_INTERVAL_3_RES_HEADER_CONFIG
471487
assert_equal("test", d.instance.tag)
472488
assert_equal(3, d.instance.interval)
@@ -483,6 +499,61 @@ class HttpPullInputTest < Test::Unit::TestCase
483499
assert(time.is_a?(Fluent::EventTime))
484500
end
485501
end
502+
503+
test 'interval 3 with multiple header' do
504+
d = create_driver TEST_INTERVAL_3_RES_MULTI_HEADER_CONFIG
505+
assert_equal("test", d.instance.tag)
506+
assert_equal(3, d.instance.interval)
507+
508+
d.run(timeout: 8) do
509+
sleep 7
510+
end
511+
assert_equal(2, d.events.size)
512+
513+
d.events.each do |tag, time, record|
514+
assert_equal("test", tag)
515+
516+
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200,"message"=>{"status"=>"OK"},"header"=>{"Content-Type"=>"application/json","Content-Length"=>"18"}}, record)
517+
assert(time.is_a?(Fluent::EventTime))
518+
end
519+
end
520+
end
521+
522+
sub_test_case "custom request header" do
523+
TEST_INTERVAL_3_CUSTOM_HEADER_CONFIG = %[
524+
tag test
525+
url http://127.0.0.1:3939/custom_header
526+
527+
interval 3s
528+
format json
529+
530+
<request_header>
531+
header HATSUNE-MIKU
532+
value 3939
533+
</request_header>
534+
535+
<response_header>
536+
header HATSUNE-MIKU
537+
</response_header>
538+
]
539+
540+
test 'interval 3 with single header' do
541+
d = create_driver TEST_INTERVAL_3_CUSTOM_HEADER_CONFIG
542+
assert_equal("test", d.instance.tag)
543+
assert_equal(3, d.instance.interval)
544+
545+
d.run(timeout: 8) do
546+
sleep 7
547+
end
548+
assert_equal(2, d.events.size)
549+
550+
d.events.each do |tag, time, record|
551+
assert_equal("test", tag)
552+
553+
assert_equal({"url"=>"http://127.0.0.1:3939/custom_header","status"=>200,"message"=>{"status"=>"OK"},"header"=>{"HATSUNE-MIKU"=>"3939"}}, record)
554+
assert(time.is_a?(Fluent::EventTime))
555+
end
556+
end
486557
end
487558

488559
private

0 commit comments

Comments
 (0)