diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-06 03:08:02 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-06 03:08:02 +0000 |
commit | ed73d4f207ef6cb8646719baa1188d096c9f3139 (patch) | |
tree | dea7ab9906154c73204a0361163e30500f929d44 /spec/models/clusters | |
parent | 2349eabc1a473bfb70555f0ce6d3d808cecb181d (diff) | |
download | gitlab-ce-ed73d4f207ef6cb8646719baa1188d096c9f3139.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/clusters')
-rw-r--r-- | spec/models/clusters/applications/prometheus_spec.rb | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb index 2aeb7e5a990..cf6e3fff744 100644 --- a/spec/models/clusters/applications/prometheus_spec.rb +++ b/spec/models/clusters/applications/prometheus_spec.rb @@ -53,6 +53,16 @@ describe Clusters::Applications::Prometheus do end describe '#prometheus_client' do + shared_examples 'exception caught for prometheus client' do + before do + allow(kube_client).to receive(:proxy_url).and_raise(exception) + end + + it 'returns nil' do + expect(subject.prometheus_client).to be_nil + end + end + context 'cluster is nil' do it 'returns nil' do expect(subject.cluster).to be_nil @@ -98,12 +108,18 @@ describe Clusters::Applications::Prometheus do end context 'when cluster is not reachable' do - before do - allow(kube_client).to receive(:proxy_url).and_raise(Kubeclient::HttpError.new(401, 'Unauthorized', nil)) + it_behaves_like 'exception caught for prometheus client' do + let(:exception) { Kubeclient::HttpError.new(401, 'Unauthorized', nil) } + end + end + + context 'when there is a socket error while contacting cluster' do + it_behaves_like 'exception caught for prometheus client' do + let(:exception) { Errno::ECONNREFUSED } end - it 'returns nil' do - expect(subject.prometheus_client).to be_nil + it_behaves_like 'exception caught for prometheus client' do + let(:exception) { Errno::ECONNRESET } end end end @@ -289,4 +305,28 @@ describe Clusters::Applications::Prometheus do end end end + + describe '#configured?' do + let(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) } + + subject { prometheus.configured? } + + context 'when a kubenetes client is present' do + let(:cluster) { create(:cluster, :project, :provided_by_gcp) } + + it { is_expected.to be_truthy } + + context 'when it is not availalble' do + let(:prometheus) { create(:clusters_applications_prometheus, cluster: cluster) } + + it { is_expected.to be_falsey } + end + end + + context 'when a kubenetes client is not present' do + let(:cluster) { create(:cluster) } + + it { is_expected.to be_falsy } + end + end end |