From 0e90284c11815f84c804e7e922e709b31ca6d029 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Wed, 7 Feb 2018 02:25:54 +0100 Subject: Catch json parsing error as PrometheusError --- spec/lib/gitlab/prometheus_client_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/lib/gitlab') diff --git a/spec/lib/gitlab/prometheus_client_spec.rb b/spec/lib/gitlab/prometheus_client_spec.rb index 575b7805e33..5d86007f71f 100644 --- a/spec/lib/gitlab/prometheus_client_spec.rb +++ b/spec/lib/gitlab/prometheus_client_spec.rb @@ -47,6 +47,16 @@ describe Gitlab::PrometheusClient do expect(req_stub).to have_been_requested end end + + context 'when request returns non json data' do + it 'raises a Gitlab::PrometheusError error' do + req_stub = stub_prometheus_request(query_url, status: 200, body: 'not json') + + expect { execute_query } + .to raise_error(Gitlab::PrometheusError, 'Parsing response failed') + expect(req_stub).to have_been_requested + end + end end describe 'failure to reach a provided prometheus url' do -- cgit v1.2.1