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 ...@@ -129,14 +129,12 @@ module Integrations
end end
def test(data) def test(data)
begin result = execute(data)
result = execute(data)
return { success: false, result: result[:message] } if result[:http_status] != 200 {
rescue StandardError => error success: (200..299).cover?(result[:http_status]),
return { success: false, result: error } result: result[:message]
end }
{ success: true, result: result[:message] }
end end
private private
......
...@@ -140,21 +140,29 @@ RSpec.describe Integrations::Datadog do ...@@ -140,21 +140,29 @@ RSpec.describe Integrations::Datadog do
end end
describe '#test' do describe '#test' do
context 'when request is succesful' do subject(:result) { saved_instance.test(pipeline_data) }
subject { saved_instance.test(pipeline_data) }
before do let(:body) { 'OK' }
stub_request(:post, expected_hook_url).to_return(body: 'OK') let(:status) { 200 }
end
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' }) } it { is_expected.to eq({ success: true, result: 'OK' }) }
end end
context 'when request fails' do context 'when request is successful with a HTTP 202 status' do
subject { saved_instance.test(pipeline_data) } 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!!!' }) } it { is_expected.to eq({ success: false, result: 'CRASH!!!' }) }
end end
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