Commit 9b310f62 authored by Nikola Milojevic's avatar Nikola Milojevic

Merge branch 'fix-datadog-testing-http-response' into 'master'

Accept all 2xx HTTP responses when testing the Datadog integration

See merge request gitlab-org/gitlab!67524
parents 87bca6b9 6f113615
......@@ -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] }
{
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) }
let(:body) { 'OK' }
let(:status) { 200 }
before do
stub_request(:post, expected_hook_url).to_return(body: 'OK')
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 }
before do
stub_request(:post, expected_hook_url).to_return(body: 'CRASH!!!', status: 500)
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!!!' }
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