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 ...@@ -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
return { success: false, result: error }
end
{ success: true, result: result[:message] } {
success: (200..299).cover?(result[:http_status]),
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) }
let(:body) { 'OK' }
let(:status) { 200 }
before do 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 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 }
before do it { is_expected.to eq({ success: true, result: 'OK' }) }
stub_request(:post, expected_hook_url).to_return(body: 'CRASH!!!', status: 500)
end 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!!!' }) } 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