Commit 6f113615 authored by Markus Koller's avatar Markus Koller

Accept all 2xx HTTP responses when testing the Datadog integration

The Datadog API sometimes responds with a HTTP 202 response status,
which results in an error message when testing the integration settings
even though the request shows up as successful in the delivery log.

This changes the test to accept all 2xx HTTP status codes.

Changelog: fixed
parent e7ea1609
......@@ -129,14 +129,12 @@ module Integrations
end
def test(data)
begin
result = execute(data)
return { success: false, result: result[:message] } if result[:http_status] != 200
rescue StandardError => error
return { success: false, result: error }
end
{ success: true, result: result[:message] }
result = execute(data)
{
success: (200..299).cover?(result[:http_status]),
result: result[:message]
}
end
private
......
......@@ -140,21 +140,29 @@ RSpec.describe Integrations::Datadog do
end
describe '#test' do
context 'when request is succesful' do
subject { saved_instance.test(pipeline_data) }
subject(:result) { saved_instance.test(pipeline_data) }
before do
stub_request(:post, expected_hook_url).to_return(body: 'OK')
end
let(:body) { 'OK' }
let(:status) { 200 }
before do
stub_request(:post, expected_hook_url).to_return(body: body, status: status)
end
context 'when request is successful with a HTTP 200 status' do
it { is_expected.to eq({ success: true, result: 'OK' }) }
end
context 'when request fails' do
subject { saved_instance.test(pipeline_data) }
context 'when request is successful with a HTTP 202 status' do
let(:status) { 202 }
it { is_expected.to eq({ success: true, result: 'OK' }) }
end
context 'when request fails with a HTTP 500 status' do
let(:status) { 500 }
let(:body) { 'CRASH!!!' }
before do
stub_request(:post, expected_hook_url).to_return(body: 'CRASH!!!', status: 500)
end
it { is_expected.to eq({ success: false, result: 'CRASH!!!' }) }
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment