diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/lib/gitlab/prometheus_client_spec.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/lib/gitlab/prometheus_client_spec.rb')
-rw-r--r-- | spec/lib/gitlab/prometheus_client_spec.rb | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/spec/lib/gitlab/prometheus_client_spec.rb b/spec/lib/gitlab/prometheus_client_spec.rb index 0774c2f3144..82ef4675553 100644 --- a/spec/lib/gitlab/prometheus_client_spec.rb +++ b/spec/lib/gitlab/prometheus_client_spec.rb @@ -36,6 +36,28 @@ RSpec.describe Gitlab::PrometheusClient do end end + describe '#ready?' do + it 'returns true when status code is 200' do + stub_request(:get, subject.ready_url).to_return(status: 200, body: 'Prometheus is Ready.\n') + + expect(subject.ready?).to eq(true) + end + + it 'returns false when status code is not 200' do + [503, 500].each do |code| + stub_request(:get, subject.ready_url).to_return(status: code, body: 'Service Unavailable') + + expect(subject.ready?).to eq(false) + end + end + + it 'raises error when ready api throws exception' do + stub_request(:get, subject.ready_url).to_raise(Net::OpenTimeout) + + expect { subject.ready? }.to raise_error(Gitlab::PrometheusClient::UnexpectedResponseError) + end + end + # This shared examples expect: # - query_url: A query URL # - execute_query: A query call @@ -136,7 +158,7 @@ RSpec.describe Gitlab::PrometheusClient do let(:query_url) { prometheus_query_with_time_url(prometheus_query, Time.now.utc) } around do |example| - Timecop.freeze { example.run } + freeze_time { example.run } end context 'when request returns vector results' do @@ -195,7 +217,7 @@ RSpec.describe Gitlab::PrometheusClient do let(:query_url) { prometheus_query_with_time_url(query, Time.now.utc) } around do |example| - Timecop.freeze { example.run } + freeze_time { example.run } end context 'when request returns vector results' do @@ -228,7 +250,7 @@ RSpec.describe Gitlab::PrometheusClient do let(:query_url) { prometheus_series_url('series_name', 'other_service') } around do |example| - Timecop.freeze { example.run } + freeze_time { example.run } end it 'calls endpoint and returns list of series' do @@ -259,7 +281,7 @@ RSpec.describe Gitlab::PrometheusClient do let(:query_url) { prometheus_query_range_url(prometheus_query) } around do |example| - Timecop.freeze { example.run } + freeze_time { example.run } end context 'when non utc time is passed' do @@ -358,7 +380,7 @@ RSpec.describe Gitlab::PrometheusClient do let(:query_url) { prometheus_query_url(prometheus_query) } around do |example| - Timecop.freeze { example.run } + freeze_time { example.run } end context 'when response status code is 200' do |