spec/outputs/http_spec.rb in logstash-output-http-4.4.0 vs spec/outputs/http_spec.rb in logstash-output-http-5.0.0

- old
+ new

@@ -1,11 +1,10 @@ require "logstash/devutils/rspec/spec_helper" require "logstash/outputs/http" require "logstash/codecs/plain" require "thread" require "sinatra" -require_relative "../supports/compressed_requests" PORT = rand(65535-1024) + 1025 class LogStash::Outputs::Http attr_writer :agent @@ -15,14 +14,12 @@ # note that Sinatra startup and shutdown messages are directly logged to stderr so # it is not really possible to disable them without reopening stderr which is not advisable. # # == Sinatra (v1.4.6) has taken the stage on 51572 for development with backup from WEBrick # == Sinatra has ended his set (crowd applauds) -# + class TestApp < Sinatra::Base - # on the fly uncompress gzip content - use CompressedRequests # disable WEBrick logging def self.server_settings { :AccessLog => [], :Logger => WEBrick::BasicLog::new(nil, WEBrick::BasicLog::FATAL) } end @@ -39,15 +36,15 @@ end def self.last_request @last_request end - + def self.retry_fail_count=(count) @retry_fail_count = count end - + def self.retry_fail_count() @retry_fail_count end multiroute(%w(get post put patch delete), "/good") do @@ -57,14 +54,14 @@ multiroute(%w(get post put patch delete), "/bad") do self.class.last_request = request [400, "YUP"] end - + multiroute(%w(get post put patch delete), "/retry") do self.class.last_request = request - + if self.class.retry_fail_count > 0 self.class.retry_fail_count -= 1 [429, "Will succeed in #{self.class.retry_fail_count}"] else [200, "Done Retrying"] @@ -81,11 +78,11 @@ proc do begin app.run!(opts) do |server| queue.push("started") end - rescue => e + rescue => e puts "Error in webserver thread #{e}" # ignore end end ) @@ -159,11 +156,11 @@ it "should log a failure" do expect(subject).to have_received(:log_failure).with(any_args) end end - + context "with ignorable failing requests" do let(:url) { "http://localhost:#{port}/bad"} let(:verb_behavior_config) { super.merge("ignorable_codes" => [400]) } before do @@ -172,11 +169,11 @@ it "should log a failure" do expect(subject).not_to have_received(:log_failure).with(any_args) end end - + context "with retryable failing requests" do let(:url) { "http://localhost:#{port}/retry"} before do TestApp.retry_fail_count=2 @@ -185,16 +182,16 @@ end it "should log a failure 2 times" do expect(subject).to have_received(:log_failure).with(any_args).twice end - + it "should make three total requests" do expect(subject).to have_received(:send_event).exactly(3).times end - end - + end + end end LogStash::Outputs::Http::VALID_METHODS.each do |method| context "when using '#{method}'" do @@ -226,12 +223,11 @@ it "should have the correct content type" do expect(content_type).to eql(expected_content_type) end end - shared_examples "integration tests" do - let(:base_config) { {} } + describe "integration tests" do let(:url) { "http://localhost:#{port}/good" } let(:event) { LogStash::Event.new("foo" => "bar", "baz" => "bot", "user" => "McBest") } @@ -241,51 +237,51 @@ subject.register end describe "sending with the default (JSON) config" do let(:config) { - base_config.merge({"url" => url, "http_method" => "post", "pool_max" => 1}) + {"url" => url, "http_method" => "post", "pool_max" => 1} } let(:expected_body) { LogStash::Json.dump(event) } let(:expected_content_type) { "application/json" } include_examples("a received event") end describe "sending the event as a form" do let(:config) { - base_config.merge({"url" => url, "http_method" => "post", "pool_max" => 1, "format" => "form"}) + {"url" => url, "http_method" => "post", "pool_max" => 1, "format" => "form"} } let(:expected_body) { subject.send(:encode, event.to_hash) } let(:expected_content_type) { "application/x-www-form-urlencoded" } include_examples("a received event") end describe "sending the event as a message" do let(:config) { - base_config.merge({"url" => url, "http_method" => "post", "pool_max" => 1, "format" => "message", "message" => "%{foo} AND %{baz}"}) + {"url" => url, "http_method" => "post", "pool_max" => 1, "format" => "message", "message" => "%{foo} AND %{baz}"} } let(:expected_body) { "#{event.get("foo")} AND #{event.get("baz")}" } let(:expected_content_type) { "text/plain" } include_examples("a received event") end describe "sending a mapped event" do let(:config) { - base_config.merge({"url" => url, "http_method" => "post", "pool_max" => 1, "mapping" => {"blah" => "X %{foo}"} }) + {"url" => url, "http_method" => "post", "pool_max" => 1, "mapping" => {"blah" => "X %{foo}"} } } let(:expected_body) { LogStash::Json.dump("blah" => "X #{event.get("foo")}") } let(:expected_content_type) { "application/json" } include_examples("a received event") end describe "sending a mapped, nested event" do let(:config) { - base_config.merge({ + { "url" => url, "http_method" => "post", "pool_max" => 1, "mapping" => { "host" => "X %{foo}", @@ -294,11 +290,11 @@ }, "arrayevent" => [{ "user" => "Z %{user}" }] } - }) + } } let(:expected_body) { LogStash::Json.dump({ "host" => "X #{event.get("foo")}", "event" => { @@ -310,18 +306,8 @@ }) } let(:expected_content_type) { "application/json" } include_examples("a received event") - end - end - - describe "integration test without gzip compression" do - include_examples("integration tests") - end - - describe "integration test with gzip compression" do - include_examples("integration tests") do - let(:base_config) { { "http_compression" => true } } end end end