test/plugin/test_in_http.rb in fluentd-0.12.0.pre.3 vs test/plugin/test_in_http.rb in fluentd-0.12.0

- old
+ new

@@ -11,10 +11,11 @@ CONFIG = %[ port #{PORT} bind "127.0.0.1" body_size_limit 10m keepalive_timeout 5 + respond_with_empty_img true ] def create_driver(conf=CONFIG) Fluent::Test::InputTestDriver.new(Fluent::HttpInput).configure(conf, true) end @@ -197,10 +198,29 @@ assert_equal "200", res.code } end end + def test_resonse_with_empty_img + d = create_driver(CONFIG + "respond_with_empty_img true") + assert_equal true, d.instance.respond_with_empty_img + + time = Time.parse("2011-01-02 13:14:15 UTC").to_i + + d.expect_emit "tag1", time, {"a"=>1} + d.expect_emit "tag2", time, {"a"=>2} + + d.run do + d.expected_emits.each {|tag,time,record| + res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s}) + assert_equal "200", res.code + # Ruby returns ASCII-8 encoded string for GIF. + assert_equal Fluent::HttpInput::EMPTY_GIF_IMAGE, res.body.force_encoding("UTF-8") + } + end + end + def test_if_content_type_is_initialized_properly # This test is to check if Fluent::HttpInput::Handler's @content_type is initialized properly. # Especially when in Keep-Alive and the second request has no 'Content-Type'. # # Actually, in the current implementation of in_http, we can't test it directly. @@ -212,20 +232,20 @@ orig_handler = Fluent::HttpInput::Handler begin # Create the extended Handler which can store @content_type per request ext_handler = Class.new(Fluent::HttpInput::Handler) do - @@content_types = [] + @@content_types = [] - def self.content_types - @@content_types - end + def self.content_types + @@content_types + end - def on_message_complete - @@content_types << @content_type - super - end + def on_message_complete + @@content_types << @content_type + super end + end # Replace the original Handler temporally with the extended one Fluent::HttpInput.module_eval do remove_const(:Handler) if const_defined?(:Handler) const_set(:Handler, ext_handler)