Skip to content

Commit fab3862

Browse files
add testcase for http method
1 parent 8bc363a commit fab3862

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

test/helper/stub_server.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
require 'webrick'
22

3+
class DeleteService < WEBrick::HTTPServlet::AbstractServlet
4+
def service(req, res)
5+
if req.request_method != "DELETE"
6+
res.status = 405
7+
else
8+
res.status = 200
9+
res['Content-Type'] = 'application/json'
10+
res.body = '{ "status": "OK" }'
11+
end
12+
end
13+
end
14+
315
class StubServer
416
def initialize
517
create_server
@@ -12,6 +24,9 @@ def initialize
1224
@server.mount_proc '/redirect', &method(:redirect)
1325
@server.mount_proc '/protected', &method(:protected)
1426
@server.mount_proc '/custom_header', &method(:custom_header)
27+
28+
@server.mount_proc '/method_post', &method(:method_post)
29+
@server.mount '/method_delete', DeleteService
1530
end
1631

1732
def start
@@ -90,4 +105,15 @@ def custom_header(req, res)
90105
res['Content-Type'] = 'application/json'
91106
res.body = '{ "status": "OK" }'
92107
end
108+
109+
def method_post(req, res)
110+
if req.request_method != "POST"
111+
res.status = 405
112+
else
113+
res.status = 200
114+
res['Content-Type'] = 'application/json'
115+
res.body = '{ "status": "OK" }'
116+
end
117+
end
93118
end
119+

test/plugin/test_in_http_pull.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,62 @@ class HttpPullInputTest < Test::Unit::TestCase
563563
end
564564
end
565565

566+
sub_test_case "request method" do
567+
TEST_INTERVAL_3_POST = %[
568+
tag test
569+
url http://127.0.0.1:3939/method_post
570+
571+
interval 3s
572+
format json
573+
http_method post
574+
]
575+
576+
TEST_INTERVAL_3_DELETE = %[
577+
tag test
578+
url http://127.0.0.1:3939/method_delete
579+
580+
interval 3s
581+
format json
582+
http_method delete
583+
]
584+
585+
test 'interval 3 with :post' do
586+
d = create_driver TEST_INTERVAL_3_POST
587+
assert_equal("test", d.instance.tag)
588+
assert_equal(3, d.instance.interval)
589+
590+
d.run(timeout: 8) do
591+
sleep 7
592+
end
593+
assert_equal(2, d.events.size)
594+
595+
d.events.each do |tag, time, record|
596+
assert_equal("test", tag)
597+
598+
assert_equal({"url"=>"http://127.0.0.1:3939/method_post","status"=>200, "message"=>{"status"=>"OK"}}, record)
599+
assert(time.is_a?(Fluent::EventTime))
600+
end
601+
end
602+
603+
test 'interval 3 with :delete' do
604+
d = create_driver TEST_INTERVAL_3_DELETE
605+
assert_equal("test", d.instance.tag)
606+
assert_equal(3, d.instance.interval)
607+
608+
d.run(timeout: 8) do
609+
sleep 7
610+
end
611+
assert_equal(2, d.events.size)
612+
613+
d.events.each do |tag, time, record|
614+
assert_equal("test", tag)
615+
616+
assert_equal({"url"=>"http://127.0.0.1:3939/method_delete","status"=>200, "message"=>{"status"=>"OK"}}, record)
617+
assert(time.is_a?(Fluent::EventTime))
618+
end
619+
end
620+
end
621+
566622
private
567623

568624
def create_driver(conf)

0 commit comments

Comments
 (0)