diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/services/clusters/applications/prometheus_update_service_spec.rb | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/services/clusters/applications/prometheus_update_service_spec.rb')
-rw-r--r-- | spec/services/clusters/applications/prometheus_update_service_spec.rb | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/spec/services/clusters/applications/prometheus_update_service_spec.rb b/spec/services/clusters/applications/prometheus_update_service_spec.rb deleted file mode 100644 index 615bfc44045..00000000000 --- a/spec/services/clusters/applications/prometheus_update_service_spec.rb +++ /dev/null @@ -1,111 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Clusters::Applications::PrometheusUpdateService do - describe '#execute' do - let(:project) { create(:project) } - let(:environment) { create(:environment, project: project) } - let(:cluster) { create(:cluster, :provided_by_user, :with_installed_helm, projects: [project]) } - let(:application) { create(:clusters_applications_prometheus, :installed, cluster: cluster) } - let(:empty_alerts_values_update_yaml) { "---\nalertmanager:\n enabled: false\nserverFiles:\n alerts: {}\n" } - let(:helm_client) { instance_double(::Gitlab::Kubernetes::Helm::API) } - - subject(:service) { described_class.new(application, project) } - - context 'when prometheus is a Clusters::Integrations::Prometheus' do - let(:application) { create(:clusters_integrations_prometheus, cluster: cluster) } - - it 'raises NotImplementedError' do - expect { service.execute }.to raise_error(NotImplementedError) - end - end - - context 'when prometheus is externally installed' do - let(:application) { create(:clusters_applications_prometheus, :externally_installed, cluster: cluster) } - - it 'raises NotImplementedError' do - expect { service.execute }.to raise_error(NotImplementedError) - end - end - - context 'when prometheus is a Clusters::Applications::Prometheus' do - let!(:patch_command) { application.patch_command(empty_alerts_values_update_yaml) } - - before do - allow(service).to receive(:patch_command).with(empty_alerts_values_update_yaml).and_return(patch_command) - allow(service).to receive(:helm_api).and_return(helm_client) - end - - context 'when there are no errors' do - before do - expect(helm_client).to receive(:update).with(patch_command) - - allow(::ClusterWaitForAppUpdateWorker) - .to receive(:perform_in) - .and_return(nil) - end - - it 'make the application updating' do - expect(application.cluster).not_to be_nil - - service.execute - - expect(application).to be_updating - end - - it 'updates current config' do - prometheus_config_service = spy(:prometheus_config_service) - - expect(Clusters::Applications::PrometheusConfigService) - .to receive(:new) - .with(project, cluster, application) - .and_return(prometheus_config_service) - - expect(prometheus_config_service) - .to receive(:execute) - .and_return(YAML.safe_load(empty_alerts_values_update_yaml)) - - service.execute - end - - it 'schedules async update status check' do - expect(::ClusterWaitForAppUpdateWorker).to receive(:perform_in).once - - service.execute - end - end - - context 'when k8s cluster communication fails' do - before do - error = ::Kubeclient::HttpError.new(500, 'system failure', nil) - allow(helm_client).to receive(:update).and_raise(error) - end - - it 'make the application update errored' do - service.execute - - expect(application).to be_update_errored - expect(application.status_reason).to match(/kubernetes error:/i) - end - end - - context 'when application cannot be persisted' do - let(:application) { build(:clusters_applications_prometheus, :installed) } - - before do - allow(application).to receive(:make_updating!).once - .and_raise(ActiveRecord::RecordInvalid.new(application)) - end - - it 'make the application update errored' do - expect(helm_client).not_to receive(:update) - - service.execute - - expect(application).to be_update_errored - end - end - end - end -end |