Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJose Ivan Vargas <jvargas@gitlab.com>2017-05-03 00:53:49 +0300
committerJose Ivan Vargas <jvargas@gitlab.com>2017-05-04 21:56:26 +0300
commit64e811957795293b647bda7aef23ffbd92082614 (patch)
treea988937a8af241c4e79c7d92e6da7c17bd09ddbd /spec
parent63a5d98a7c921289e9b43f4b54c03614427f7eda (diff)
Improved code styling and added a HTTParty rescue block
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/prometheus_spec.rb34
-rw-r--r--spec/models/project_services/prometheus_service_spec.rb5
-rw-r--r--spec/support/prometheus_helpers.rb10
3 files changed, 27 insertions, 22 deletions
diff --git a/spec/lib/gitlab/prometheus_spec.rb b/spec/lib/gitlab/prometheus_spec.rb
index d8683669518..8e187df6ca4 100644
--- a/spec/lib/gitlab/prometheus_spec.rb
+++ b/spec/lib/gitlab/prometheus_spec.rb
@@ -49,21 +49,33 @@ describe Gitlab::Prometheus, lib: true do
end
end
- describe 'failure to reach a prometheus url' do
- prometheus_invalid_url = 'https://prometheus.invalid.example.com'
+ describe 'failure to reach a provided prometheus url' do
+ let(:prometheus_url) {"https://prometheus.invalid.example.com"}
- it 'raises a Gitlab::PrometheusError error when a SocketError is rescued' do
- req_stub = stub_prometheus_request_with_socket_exception(prometheus_invalid_url)
+ context 'exceptions are raised' do
+ it 'raises a Gitlab::PrometheusError error when a SocketError is rescued' do
+ req_stub = stub_prometheus_request_with_exception(prometheus_url, SocketError)
- expect { subject.send(:get, prometheus_invalid_url) }.to raise_error(Gitlab::PrometheusError, "Can't connect to #{prometheus_invalid_url}")
- expect(req_stub).to have_been_requested
- end
+ expect { subject.send(:get, prometheus_url) }
+ .to raise_error(Gitlab::PrometheusError, "Can't connect to #{prometheus_url}")
+ expect(req_stub).to have_been_requested
+ end
- it 'raises a Gitlab::PrometheusError error when a SSLError is rescued' do
- req_stub = stub_prometheus_request_with_ssl_exception(prometheus_invalid_url)
+ it 'raises a Gitlab::PrometheusError error when a SSLError is rescued' do
+ req_stub = stub_prometheus_request_with_exception(prometheus_url, OpenSSL::SSL::SSLError)
- expect { subject.send(:get, prometheus_invalid_url) }.to raise_error(Gitlab::PrometheusError, "#{prometheus_invalid_url} contains invalid SSL data")
- expect(req_stub).to have_been_requested
+ expect { subject.send(:get, prometheus_url) }
+ .to raise_error(Gitlab::PrometheusError, "#{prometheus_url} contains invalid SSL data")
+ expect(req_stub).to have_been_requested
+ end
+
+ it 'raises a Gitlab::PrometheusError error when a HTTParty::Error is rescued' do
+ req_stub = stub_prometheus_request_with_exception(prometheus_url, HTTParty::Error)
+
+ expect { subject.send(:get, prometheus_url) }
+ .to raise_error(Gitlab::PrometheusError, "An error has ocurred")
+ expect(req_stub).to have_been_requested
+ end
end
end
diff --git a/spec/models/project_services/prometheus_service_spec.rb b/spec/models/project_services/prometheus_service_spec.rb
index 5ef1b53be15..f3126bc1e57 100644
--- a/spec/models/project_services/prometheus_service_spec.rb
+++ b/spec/models/project_services/prometheus_service_spec.rb
@@ -93,12 +93,11 @@ describe PrometheusService, models: true, caching: true do
[404, 500].each do |status|
context "when Prometheus responds with #{status}" do
- body_response = 'QUERY_FAILED'
before do
- stub_all_prometheus_requests(environment.slug, status: status, body: body_response)
+ stub_all_prometheus_requests(environment.slug, status: status, body: "QUERY FAILED!")
end
- it { is_expected.to eq(success: false, result: %(#{status} - \"#{body_response}\")) }
+ it { is_expected.to eq(success: false, result: %(#{status} - "QUERY FAILED!")) }
end
end
end
diff --git a/spec/support/prometheus_helpers.rb b/spec/support/prometheus_helpers.rb
index 625a40e1154..a204365431b 100644
--- a/spec/support/prometheus_helpers.rb
+++ b/spec/support/prometheus_helpers.rb
@@ -33,14 +33,8 @@ module PrometheusHelpers
})
end
- def stub_prometheus_request_with_socket_exception(url)
- WebMock.stub_request(:get, url)
- .to_raise(SocketError)
- end
-
- def stub_prometheus_request_with_ssl_exception(url)
- WebMock.stub_request(:get, url)
- .to_raise(OpenSSL::SSL::SSLError)
+ def stub_prometheus_request_with_exception(url, exception_type)
+ WebMock.stub_request(:get, url).to_raise(exception_type)
end
def stub_all_prometheus_requests(environment_slug, body: nil, status: 200)