diff options
Diffstat (limited to 'spec/models/clusters/applications/prometheus_spec.rb')
-rw-r--r-- | spec/models/clusters/applications/prometheus_spec.rb | 94 |
1 files changed, 15 insertions, 79 deletions
diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb index 032de6aa7c2..5a0ccabd467 100644 --- a/spec/models/clusters/applications/prometheus_spec.rb +++ b/spec/models/clusters/applications/prometheus_spec.rb @@ -39,6 +39,19 @@ RSpec.describe Clusters::Applications::Prometheus do end end + describe 'transition to externally_installed' do + let(:project) { create(:project) } + let(:cluster) { create(:cluster, :with_installed_helm) } + let(:application) { create(:clusters_applications_prometheus, :installing, cluster: cluster) } + + it 'schedules post installation job' do + expect(Clusters::Applications::ActivateServiceWorker) + .to receive(:perform_async).with(cluster.id, 'prometheus') + + application.make_externally_installed! + end + end + describe 'transition to updating' do let(:project) { create(:project) } let(:cluster) { create(:cluster, projects: [project]) } @@ -61,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 |