spec/outputs/http_spec.rb in logstash-output-http-5.1.2 vs spec/outputs/http_spec.rb in logstash-output-http-5.2.0

- old
+ new

@@ -45,11 +45,11 @@ def self.retry_fail_count=(count) @retry_fail_count = count end def self.retry_fail_count() - @retry_fail_count + @retry_fail_count || 2 end multiroute(%w(get post put patch delete), "/good") do self.class.last_request = request [200, "YUP"] @@ -124,10 +124,11 @@ subject.register allow(client_proxy).to receive(:send). with(expected_method, url, anything). and_call_original allow(subject).to receive(:log_failure).with(any_args) + allow(subject).to receive(:log_retryable_response).with(any_args) end context 'sending no events' do it 'should not block the pipeline' do subject.multi_receive([]) @@ -188,12 +189,12 @@ TestApp.retry_fail_count=2 allow(subject).to receive(:send_event).and_call_original subject.multi_receive([event]) end - it "should log a failure 2 times" do - expect(subject).to have_received(:log_failure).with(any_args).twice + it "should log a retryable response 2 times" do + expect(subject).to have_received(:log_retryable_response).with(any_args).twice end it "should make three total requests" do expect(subject).to have_received(:send_event).exactly(3).times end @@ -211,28 +212,47 @@ shared_examples("a received event") do before do TestApp.last_request = nil end - before do - subject.multi_receive([event]) - end + let(:events) { [event] } - let(:last_request) { TestApp.last_request } - let(:body) { last_request.body.read } - let(:content_type) { last_request.env["CONTENT_TYPE"] } + describe "with a good code" do + before do + subject.multi_receive(events) + end - it "should receive the request" do - expect(last_request).to be_truthy - end + let(:last_request) { TestApp.last_request } + let(:body) { last_request.body.read } + let(:content_type) { last_request.env["CONTENT_TYPE"] } - it "should receive the event as a hash" do - expect(body).to eql(expected_body) + it "should receive the request" do + expect(last_request).to be_truthy + end + + it "should receive the event as a hash" do + expect(body).to eql(expected_body) + end + + it "should have the correct content type" do + expect(content_type).to eql(expected_content_type) + end end - it "should have the correct content type" do - expect(content_type).to eql(expected_content_type) + describe "a retryable code" do + let(:url) { "http://localhost:#{port}/retry" } + + before do + TestApp.retry_fail_count=2 + allow(subject).to receive(:send_event).and_call_original + allow(subject).to receive(:log_retryable_response) + subject.multi_receive(events) + end + + it "should retry" do + expect(subject).to have_received(:log_retryable_response).with(any_args).twice + end end end shared_examples "integration tests" do let(:base_config) { {} } @@ -253,9 +273,22 @@ } let(:expected_body) { LogStash::Json.dump(event) } let(:expected_content_type) { "application/json" } include_examples("a received event") + end + + describe "sending the batch as JSON" do + let(:config) do + base_config.merge({"url" => url, "http_method" => "post", "format" => "json_batch"}) + end + + let(:expected_body) { ::LogStash::Json.dump events } + let(:events) { [::LogStash::Event.new("a" => 1), ::LogStash::Event.new("b" => 2)]} + 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"})