diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-13 03:11:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-13 03:11:29 +0300 |
commit | 248057a54a1d5fb7db018ef77cda3fee2b0c8ded (patch) | |
tree | b1098b6b2839fff1d3b7b4ad1e6969f16be5d2df /spec/models/clusters | |
parent | beab869416d5720126a8cbe76f6c842a9b9d9300 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/clusters')
-rw-r--r-- | spec/models/clusters/applications/prometheus_spec.rb | 81 |
1 files changed, 2 insertions, 79 deletions
diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb index c359b1863ed..5a0ccabd467 100644 --- a/spec/models/clusters/applications/prometheus_spec.rb +++ b/spec/models/clusters/applications/prometheus_spec.rb @@ -74,85 +74,8 @@ RSpec.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 - expect(subject.prometheus_client).to be_nil - end - end - - context "cluster doesn't have kubeclient" do - let(:cluster) { create(:cluster) } - - subject { create(:clusters_applications_prometheus, cluster: cluster) } - - it 'returns nil' do - expect(subject.prometheus_client).to be_nil - end - end - - context 'cluster has kubeclient' do - let(:cluster) { create(:cluster, :project, :provided_by_gcp) } - let(:kubernetes_url) { subject.cluster.platform_kubernetes.api_url } - let(:kube_client) { subject.cluster.kubeclient.core_client } - - subject { create(:clusters_applications_prometheus, cluster: cluster) } - - before do - subject.cluster.platform_kubernetes.namespace = 'a-namespace' - stub_kubeclient_discover(cluster.platform_kubernetes.api_url) - - create(:cluster_kubernetes_namespace, - cluster: cluster, - cluster_project: cluster.cluster_project, - project: cluster.cluster_project.project) - end - - it 'creates proxy prometheus_client' do - expect(subject.prometheus_client).to be_instance_of(Gitlab::PrometheusClient) - end - - it 'merges proxy_url, options and headers from kube client with prometheus_client options' do - expect(Gitlab::PrometheusClient) - .to(receive(:new)) - .with(a_valid_url, kube_client.rest_client.options.merge({ - headers: kube_client.headers, - timeout: PrometheusAdapter::DEFAULT_PROMETHEUS_REQUEST_TIMEOUT_SEC - })) - subject.prometheus_client - end - - context 'when cluster is not reachable' do - 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_behaves_like 'exception caught for prometheus client' do - let(:exception) { Errno::ECONNRESET } - end - end - - context 'when the network is unreachable' do - it_behaves_like 'exception caught for prometheus client' do - let(:exception) { Errno::ENETUNREACH } - end - end + include_examples '#prometheus_client shared' do + let(:factory) { :clusters_applications_prometheus } end end |